From 0673cd4e69296ec912103cb3dbe00e0d9fbc3b69 Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Fri, 6 Feb 2015 09:36:47 +0100 Subject: [PATCH 1/2] Problem: test_disconnect_inproc sometimes fails Solution: add settle pause after zmq_connect Fixes #1340 --- tests/test_disconnect_inproc.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_disconnect_inproc.cpp b/tests/test_disconnect_inproc.cpp index 25461a71..90e7d14e 100644 --- a/tests/test_disconnect_inproc.cpp +++ b/tests/test_disconnect_inproc.cpp @@ -94,11 +94,10 @@ int main(int, char**) { } if (iteration == 1) { zmq_connect(subSocket, "inproc://someInProcDescriptor") && printf("zmq_connect: %s\n", zmq_strerror(errno)); - //zmq_connect(subSocket, "tcp://127.0.0.1:30010") && printf("zmq_connect: %s\n", zmq_strerror(errno)); + msleep (SETTLE_TIME); } if (iteration == 4) { zmq_disconnect(subSocket, "inproc://someInProcDescriptor") && printf("zmq_disconnect(%d): %s\n", errno, zmq_strerror(errno)); - //zmq_disconnect(subSocket, "tcp://127.0.0.1:30010") && printf("zmq_disconnect: %s\n", zmq_strerror(errno)); } if (iteration > 4 && rc == 0) break; From 594e3dccebc164502bc1cf437c8bb51108e67f55 Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Mon, 20 Apr 2015 12:51:10 +0200 Subject: [PATCH 2/2] Problem: shutdown asserts if WSASTARUP wasn't done previously This is a silly assertion that causes problems if libzmq.dll is called in some esoteric ways. Solution: if the shutdown code detects WSANOTINITIALISED, then exit silently. Fixes #1377 Fixes #1144 --- src/signaler.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/signaler.cpp b/src/signaler.cpp index a1fd72f0..914b9c1c 100644 --- a/src/signaler.cpp +++ b/src/signaler.cpp @@ -132,11 +132,14 @@ zmq::signaler_t::~signaler_t () const struct linger so_linger = { 1, 0 }; int rc = setsockopt (w, SOL_SOCKET, SO_LINGER, (const char *) &so_linger, sizeof so_linger); - wsa_assert (rc != SOCKET_ERROR); - rc = closesocket (w); - wsa_assert (rc != SOCKET_ERROR); - rc = closesocket (r); - wsa_assert (rc != SOCKET_ERROR); + // Only check shutdown if WSASTARTUP was previously done + if (rc == 0 || WSAGetLastError () != WSANOTINITIALISED) { + wsa_assert (rc != SOCKET_ERROR); + rc = closesocket (w); + wsa_assert (rc != SOCKET_ERROR); + rc = closesocket (r); + wsa_assert (rc != SOCKET_ERROR); + } #else int rc = close_wait_ms (w); errno_assert (rc == 0);