I want to create a non-blocking connect. Like this:
socket.connect(); // returns immediately
For this, I use another thread, an infinite lo
You should use the following steps for an async connect:
socket(..., SOCK_NONBLOCK, ...)
connect(fd, ...)
0
nor EINPROGRESS
, then abort with errorfd
is signalled as ready for outputgetsockopt(fd, SOL_SOCKET, SO_ERROR, ...)
No loops - unless you want to handle EINTR
.
If the client is started first, you should see the error ECONNREFUSED
in the last step. If this happens, close the socket and start from the beginning.
It is difficult to tell what's wrong with your code, without seeing more details. I suppose, that you do not abort on errors in your check_socket
operation.