connection_t *c = data;
if(c->status.connecting) {
+ /* The event loop does not protect against spurious events. Verify that we are actually connected. */
+ if (connect(c->socket, &c->address.sa, sizeof(c->address)) == 0)
+ logger(DEBUG_CONNECTIONS, LOG_DEBUG, "Error while connecting to %s (%s): redundant connect() unexpectedly succeeded", c->name, c->hostname);
+ else if (!sockisconn(sockerrno)) {
+ if (!sockalready(sockerrno)) {
+ logger(DEBUG_CONNECTIONS, LOG_DEBUG, "Error while checking connection status for %s (%s): %s", c->name, c->hostname, sockstrerror(sockerrno));
+ terminate_connection(c, false);
+ }
+ return;
+ }
+
c->status.connecting = false;
int result;
#define sockmsgsize(x) ((x) == WSAEMSGSIZE)
#define sockinprogress(x) ((x) == WSAEINPROGRESS || (x) == WSAEWOULDBLOCK)
#define sockinuse(x) ((x) == WSAEADDRINUSE)
+#define sockalready(x) ((x) == WSAEALREADY || (x) == WSAEINVAL || (x) == WSAEWOULDBLOCK) /* See MSDN for connect() */
+#define sockisconn(x) ((x) == WSAEISCONN)
#else
#define sockerrno errno
#define sockstrerror(x) strerror(x)
#define sockmsgsize(x) ((x) == EMSGSIZE)
#define sockinprogress(x) ((x) == EINPROGRESS)
#define sockinuse(x) ((x) == EADDRINUSE)
+#define sockalready(x) ((x) == EALREADY)
+#define sockisconn(x) ((x) == EISCONN)
#endif
extern unsigned int bitfield_to_int(const void *bitfield, size_t size);