dermesser / libsocket

The ultimate socket library for C and C++, supporting TCP, UDP and Unix sockets (DGRAM and STREAM) on Linux, FreeBSD, Solaris. See also my uvco library for a refreshed version!
https://borgac.net/~lbo/doc/libsocket/
Other
797 stars 195 forks source link

Allow non-blocking client sockets to be created #80

Closed nick-piotrowski closed 2 years ago

nick-piotrowski commented 2 years ago

When SOCK_NONBLOCK is set on a socket, it will always return with one of these three errnos: EINPROGRESS, EALREADY, EINTR, so libsocket would reject the connection as failed. With this change, it will allow through those connections if the proper flag is set and it gets one of the three accepted errors. An important note though, this will return successfully even if the target socket -doesn't exist at all-, a true failure. The way to properly check if a nonblocking socket is connected, is to see if we can read/write to it. If we can, great! If not, we probably didn't connect correctly.

dermesser commented 2 years ago

thank you!