From 1e5bce04b4169abde2096074ea7895c96e9ef3c7 Mon Sep 17 00:00:00 2001 From: Thomas Flueeli Date: Wed, 2 Feb 2011 22:59:56 +0100 Subject: [PATCH 2/2] gibber: fix TCP connection establishment on Windows --- lib/gibber/gibber-sockets.c | 9 ++++----- lib/gibber/gibber-sockets.h | 2 +- lib/gibber/gibber-tcp-transport.c | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/gibber/gibber-sockets.c b/lib/gibber/gibber-sockets.c index bcedeb5..b926f90 100644 --- a/lib/gibber/gibber-sockets.c +++ b/lib/gibber/gibber-sockets.c @@ -27,14 +27,13 @@ #include "gibber-debug.h" gboolean -gibber_connect_errno_requires_retry (void) +gibber_connect_errno_requires_retry (int err) { #ifdef G_OS_WIN32 - int err = WSAGetLastError (); - - return (err == WSAEINPROGRESS || err == WSAEALREADY); + return (err == WSAEINPROGRESS || err == WSAEALREADY || + err == WSAEWOULDBLOCK || err == WSAEINVAL); #else - return (errno == EINPROGRESS || errno == EALREADY); + return (err == EINPROGRESS || err == EALREADY); #endif } diff --git a/lib/gibber/gibber-sockets.h b/lib/gibber/gibber-sockets.h index 5cfb3c8..48ec434 100644 --- a/lib/gibber/gibber-sockets.h +++ b/lib/gibber/gibber-sockets.h @@ -32,7 +32,7 @@ G_BEGIN_DECLS -gboolean gibber_connect_errno_requires_retry (void); +gboolean gibber_connect_errno_requires_retry (int err); gboolean gibber_socket_errno_is_eafnosupport (void); gboolean gibber_socket_errno_is_eaddrinuse (void); void gibber_socket_set_error (GError **error, const gchar *context, diff --git a/lib/gibber/gibber-tcp-transport.c b/lib/gibber/gibber-tcp-transport.c index 3fb1723..6694657 100644 --- a/lib/gibber/gibber-tcp-transport.c +++ b/lib/gibber/gibber-tcp-transport.c @@ -165,6 +165,8 @@ try_to_connect (GibberTCPTransport *self) gssize native_size; gint fd; int ret; + int err; + gboolean connected = FALSE; g_assert (priv->channel != NULL); @@ -182,9 +184,17 @@ try_to_connect (GibberTCPTransport *self) g_socket_address_to_native (gaddr, &addr, sizeof (addr), NULL); ret = connect (fd, (struct sockaddr *)&addr, (gsize) native_size); +#ifdef G_OS_WIN32 + err = WSAGetLastError(); + connected = (ret == 0 || err == WSAEISCONN); +#else + err = errno; + connected = (ret == 0); +#endif + g_object_unref (gaddr); - if (ret == 0) + if (connected) { DEBUG ("connect succeeded"); @@ -193,7 +203,7 @@ try_to_connect (GibberTCPTransport *self) return FALSE; } - if (gibber_connect_errno_requires_retry ()) + if (gibber_connect_errno_requires_retry (err)) { /* We have to wait longer */ return TRUE; -- 1.7.0.2.msysgit.0