Using g_io_add_watch_full() to wait for connect() to return on a non-blocking socket returns prematurely
Submitted by Daniel Atallah
Link to original bug (#324234)
Description
Please describe the problem: I'm seeing intermittent problems while trying to use non-blocking I/O to prevent a connect() call from blocking (using g_io_add_watch_full() to wait for the connection).
What appears to be happening is that the fd is selected by an event other than the connect being successful so that when I try to actually write to the socket from my callback function, it fails and WSAGetLastError() returns WSAENOTCONN.
There doesn't appear to be a way to wait for only a connect to happen (FD_CONNECT) - the G_IO_OUT condition will trigger on FD_WRITE or FD_CONNECT.
An interesting tidbit is that if I set the G_IO_WIN32_DEBUG env. var. to enable debugging, my callback doesn't seem to get triggered until after the connect() actually completes - I'm guessing that this is because the debugging causes stuff to be delayed enough for the connect to finish.
Another thing that I've noticed is that I'm getting the same fd from my socket() call that I had just closed - is it possible that I'm getting the HUP event triggered for closing of the previous socket and that is triggering the my connect callback? (I'm using the (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) conditions (the giochannel stuff is accessed through a wrapper)).
Hopefully this makes some sense, if not let me know and I'll try to clarify. Thanks.
Steps to reproduce:
Actual results:
Expected results:
Does this happen every time?
Other information:
Version: 2.8.x