Hi, FYI, the patch below is for an old bug, also affects ZeroMQ 3.1.0 and 2.1.11 (based on the last released versions I have local copies of, I can't seem to access GH from here).
-mato ----- Forwarded message from Martin Lucina <[email protected]> ----- Date: Thu, 3 May 2012 13:08:49 +0200 From: Martin Lucina <[email protected]> To: [email protected] Cc: Martin Lucina <[email protected]> Subject: [crossroads-dev] [PATCH] Correct handling of connect() errors in tcp, ipc_connecter_t EAGAIN was being used as a translation value for EINPROGRESS, thus shadowing a real EAGAIN return value from the OS. This caused later assertions of "Invalid argument" in stream_engine.cpp when it attempted to use a socket which was not connected. I also add EINTR to mean EINPROGRESS, as per the POSIX and FreeBSD documentation which specifies that a connect() call interrupted due to a signal will complete asynchronously. Signed-off-by: Martin Lucina <[email protected]> --- src/ipc_connecter.cpp | 9 +++++---- src/tcp_connecter.cpp | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/ipc_connecter.cpp b/src/ipc_connecter.cpp index af3665c..0722532 100644 --- a/src/ipc_connecter.cpp +++ b/src/ipc_connecter.cpp @@ -133,7 +133,7 @@ void xs::ipc_connecter_t::start_connecting () } // Connection establishment may be delayed. Poll for its completion. - else if (rc == -1 && errno == EAGAIN) { + else if (rc == -1 && errno == EINPROGRESS) { xs_assert (!handle); handle = add_fd (s); set_pollout (handle); @@ -196,9 +196,10 @@ int xs::ipc_connecter_t::open () if (rc == 0) return 0; - // Asynchronous connect was launched. - if (rc == -1 && errno == EINPROGRESS) { - errno = EAGAIN; + // Translate other error codes indicating asynchronous connect has been + // launched to a uniform EINPROGRESS. + if (rc == -1 && errno == EINTR) { + errno = EINPROGRESS; return -1; } diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp index de105bb..5ae01e7 100644 --- a/src/tcp_connecter.cpp +++ b/src/tcp_connecter.cpp @@ -140,7 +140,7 @@ void xs::tcp_connecter_t::start_connecting () } // Connection establishment may be delayed. Poll for its completion. - else if (rc == -1 && errno == EAGAIN) { + else if (rc == -1 && errno == EINPROGRESS) { xs_assert (!handle); handle = add_fd (s); set_pollout (handle); @@ -236,17 +236,18 @@ int xs::tcp_connecter_t::open () if (rc == 0) return 0; - // Asynchronous connect was launched. + // Translate other error codes indicating asynchronous connect has been + // launched to a uniform EINPROGRESS. #ifdef XS_HAVE_WINDOWS if (rc == SOCKET_ERROR && (WSAGetLastError () == WSAEINPROGRESS || WSAGetLastError () == WSAEWOULDBLOCK)) { - errno = EAGAIN; + errno = EINPROGRESS; return -1; } wsa_error_to_errno (); #else - if (rc == -1 && errno == EINPROGRESS) { - errno = EAGAIN; + if (rc == -1 && errno == EINTR) { + errno = EINPROGRESS; return -1; } #endif -- 1.7.10 ----------------------------------------- Full text of this topic in Crossroads Development: http://groups.crossroads.io/r/topic/2QCfCK2pongMdlQQIzGubl To leave Crossroads Development, email mailto:[email protected]?Subject=unsubscribe Start your own free groups and site with OnlineGroups.Net http://onlinegroups.net Host your own online groups site with GroupServer http://groupserver.org ----- End forwarded message ----- -- Martin Lucina http://lucina.net/ (interwebs/blogs/rants/consulting) [email protected] (smtp/xmpp/jabber/gtalk) @matolucina (twitter) _______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
