Home » U++ Library support » U++ MT-multithreading and servers » [SOLVED] TcpSocket Connect error
Re: TcpSocket Connect error [message #42416 is a reply to message #42396] |
Wed, 12 March 2014 17:24   |
|
Thanks Mirek,
But what about the return value? I would expect TcpSocket.Connect to return true, when it has established a connection.
This is definitely not how it works, if the server is not responding.
I looked at the Linux man page on connect and for non blocking connections it says the following:
Quote: | EINPROGRESS
The socket is nonblocking and the connection cannot be completed immediately.
It is possible to select(2) or poll(2) for completion by selecting the socket for writing.
After select(2) indicates writability, use getsockopt(2) to read the SO_ERROR option at level
SOL_SOCKET to determine whether connect() completed successfully (SO_ERROR is zero) or unsuccessfully
(SO_ERROR is one of the usual error codes listed here, explaining the reason for the failure).
|
I have attached a small example showing the error and the solution mentioned in the man page:
When connecting to a non existing server, TcpSocket.Connect returns true, but fails on a subsequent write.
I have tested the example on both Windows and Linux, and both systems has the error.
So a solution could be one of these two:
1. Change TcpSocket::SetupSocket() to make a blocking socket:
Change Socket.cpp line 302 to
if(fcntl(socket, F_SETFL, (fcntl(socket, F_GETFL, 0)))) {
or
2. Implement the getsockopt call to check the connection before returning from RawConnect.
I can make a patch to RawConnect if you would prefer that solution.
[Updated on: Wed, 12 March 2014 17:25] Report message to a moderator
|
|
|
 |
|
[SOLVED] TcpSocket Connect error
By: steffen on Tue, 11 March 2014 12:35
|
 |
|
Re: TcpSocket Connect error
By: mirek on Wed, 12 March 2014 10:52
|
 |
|
Re: TcpSocket Connect error
By: steffen on Wed, 12 March 2014 17:24
|
 |
|
Re: TcpSocket Connect error
By: mirek on Wed, 12 March 2014 19:07
|
 |
|
Re: TcpSocket Connect error
By: steffen on Thu, 13 March 2014 08:28
|
 |
|
Re: TcpSocket Connect error
By: steffen on Thu, 13 March 2014 08:43
|
 |
|
Re: TcpSocket Connect error
By: mirek on Sun, 23 March 2014 17:16
|
 |
|
Re: TcpSocket Connect error
By: steffen on Mon, 24 March 2014 08:22
|
 |
|
Re: TcpSocket Connect error
By: mirek on Mon, 24 March 2014 10:21
|
 |
|
Re: TcpSocket Connect error
By: steffen on Mon, 24 March 2014 12:02
|
 |
|
Re: TcpSocket Connect error
By: mirek on Tue, 01 April 2014 19:51
|
 |
|
Re: TcpSocket Connect error
By: steffen on Wed, 02 April 2014 07:02
|
Goto Forum:
Current Time: Tue Apr 29 23:43:42 CEST 2025
Total time taken to generate the page: 0.00750 seconds
|