From c9bdcfc58486ef42946aea28d34c45c0d125a2fd Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 16 Apr 2015 00:40:32 +1000 Subject: [PATCH 01/19] allow host_os to accept mingw64 Changes the pattern for the host_os matches to *mingw* from *mingw32* to accept both mingw32 and mingw64 versions. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f0102e9d..ed616a82 100644 --- a/configure.ac +++ b/configure.ac @@ -245,7 +245,7 @@ case "${host_os}" in LIBZMQ_CHECK_LANG_FLAG_PREPEND([-Ae]) AC_CHECK_FUNCS(gethrtime) ;; - *mingw32*) + *mingw*) AC_DEFINE(ZMQ_HAVE_WINDOWS, 1, [Have Windows OS]) AC_DEFINE(ZMQ_HAVE_MINGW32, 1, [Have MinGW32]) AC_CHECK_HEADERS(windows.h) From 8957ad5edff47c28d852657cf0b69ba5ae20f11c Mon Sep 17 00:00:00 2001 From: Martin Natano Date: Fri, 17 Apr 2015 22:14:53 +0200 Subject: [PATCH 02/19] Add Bitrig to OS detection in configure.ac. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f0102e9d..d237e38a 100644 --- a/configure.ac +++ b/configure.ac @@ -225,7 +225,7 @@ case "${host_os}" in AC_DEFINE(ZMQ_FORCE_MUTEXES, 1, [Force to use mutexes]) fi ;; - *openbsd*) + *openbsd*|*bitrig*) # Define on OpenBSD to enable all library features CPPFLAGS="-D_BSD_SOURCE $CPPFLAGS" AC_DEFINE(ZMQ_HAVE_OPENBSD, 1, [Have OpenBSD OS]) From 0673cd4e69296ec912103cb3dbe00e0d9fbc3b69 Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Fri, 6 Feb 2015 09:36:47 +0100 Subject: [PATCH 03/19] 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 04/19] 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); From 30bd7c481e3151fa03ea0f32948eccebbe5b1372 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 21 Apr 2015 22:26:32 -0700 Subject: [PATCH 05/19] Fix integer narrowing issues. --- src/options.cpp | 2 +- src/plain_server.cpp | 2 +- src/socks.cpp | 19 +++++++++++-------- src/socks.hpp | 10 +++++----- src/socks_connecter.cpp | 6 +++--- src/stdint.hpp | 4 ++++ src/stream.cpp | 5 ++--- src/stream_engine.cpp | 2 +- src/tcp_connecter.cpp | 4 ++-- src/tcp_listener.cpp | 6 +++--- src/zmq_utils.cpp | 2 +- 11 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/options.cpp b/src/options.cpp index f08c595d..29eb45c8 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -96,7 +96,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, case ZMQ_IDENTITY: // Identity is any binary string from 1 to 255 octets if (optvallen_ > 0 && optvallen_ < 256) { - identity_size = optvallen_; + identity_size = (unsigned char) optvallen_; memcpy (identity, optval_, identity_size); return 0; } diff --git a/src/plain_server.cpp b/src/plain_server.cpp index f591f4e3..6a818927 100644 --- a/src/plain_server.cpp +++ b/src/plain_server.cpp @@ -265,7 +265,7 @@ int zmq::plain_server_t::produce_error (msg_t *msg_) const zmq_assert (rc == 0); char *msg_data = static_cast (msg_->data ()); memcpy (msg_data, "\5ERROR", 6); - msg_data [6] = status_code.length (); + msg_data [6] = (char) status_code.length (); memcpy (msg_data + 7, status_code.c_str (), status_code.length ()); return 0; } diff --git a/src/socks.cpp b/src/socks.cpp index f38d24a5..50e8612e 100644 --- a/src/socks.cpp +++ b/src/socks.cpp @@ -37,12 +37,10 @@ zmq::socks_greeting_t::socks_greeting_t (uint8_t method_) : } zmq::socks_greeting_t::socks_greeting_t ( - uint8_t *methods_, size_t num_methods_) + uint8_t *methods_, uint8_t num_methods_) : num_methods (num_methods_) { - zmq_assert (num_methods_ <= 255); - - for (size_t i = 0; i < num_methods_; i++) + for (uint8_t i = 0; i < num_methods_; i++) methods [i] = methods_ [i]; } @@ -55,8 +53,8 @@ void zmq::socks_greeting_encoder_t::encode (const socks_greeting_t &greeting_) uint8_t *ptr = buf; *ptr++ = 0x05; - *ptr++ = greeting_.num_methods; - for (size_t i = 0; i < greeting_.num_methods; i++) + *ptr++ = (uint8_t) greeting_.num_methods; + for (uint8_t i = 0; i < greeting_.num_methods; i++) *ptr++ = greeting_.methods [i]; bytes_encoded = 2 + greeting_.num_methods; @@ -118,10 +116,13 @@ void zmq::socks_choice_decoder_t::reset () bytes_read = 0; } + zmq::socks_request_t::socks_request_t ( uint8_t command_, std::string hostname_, uint16_t port_) : command (command_), hostname (hostname_), port (port_) -{} +{ + zmq_assert (hostname_.size () <= UINT8_MAX); +} zmq::socks_request_encoder_t::socks_request_encoder_t () : bytes_encoded (0), bytes_written (0) @@ -129,6 +130,8 @@ zmq::socks_request_encoder_t::socks_request_encoder_t () void zmq::socks_request_encoder_t::encode (const socks_request_t &req) { + zmq_assert (req.hostname.size() <= UINT8_MAX); + unsigned char *ptr = buf; *ptr++ = 0x05; *ptr++ = req.command; @@ -163,7 +166,7 @@ void zmq::socks_request_encoder_t::encode (const socks_request_t &req) } else { *ptr++ = 0x03; - *ptr++ = req.hostname.size (); + *ptr++ = (unsigned char) req.hostname.size (); memcpy (ptr, req.hostname.c_str (), req.hostname.size ()); ptr += req.hostname.size (); } diff --git a/src/socks.hpp b/src/socks.hpp index f0cf78e1..14b663a4 100644 --- a/src/socks.hpp +++ b/src/socks.hpp @@ -30,9 +30,9 @@ namespace zmq struct socks_greeting_t { socks_greeting_t (uint8_t method); - socks_greeting_t (uint8_t *methods_, size_t num_methods_); + socks_greeting_t (uint8_t *methods_, uint8_t num_methods_); - uint8_t methods [255]; + uint8_t methods [UINT8_MAX]; const size_t num_methods; }; @@ -48,7 +48,7 @@ namespace zmq private: size_t bytes_encoded; size_t bytes_written; - uint8_t buf [2 + 255]; + uint8_t buf [2 + UINT8_MAX]; }; struct socks_choice_t @@ -94,7 +94,7 @@ namespace zmq private: size_t bytes_encoded; size_t bytes_written; - uint8_t buf [4 + 256 + 2]; + uint8_t buf [4 + UINT8_MAX + 1 + 2]; }; struct socks_response_t @@ -116,7 +116,7 @@ namespace zmq void reset (); private: - uint8_t buf [4 + 256 + 2]; + int8_t buf [4 + UINT8_MAX + 1 + 2]; size_t bytes_read; }; diff --git a/src/socks_connecter.cpp b/src/socks_connecter.cpp index 7a2856e3..b6c789b3 100644 --- a/src/socks_connecter.cpp +++ b/src/socks_connecter.cpp @@ -148,7 +148,7 @@ void zmq::socks_connecter_t::in_event () // Attach the engine to the corresponding session object. send_attach (session, engine); - socket->event_connected (endpoint, s); + socket->event_connected (endpoint, (int) s); rm_fd (handle); s = -1; @@ -170,7 +170,7 @@ void zmq::socks_connecter_t::out_event () || status == sending_request); if (status == waiting_for_proxy_connection) { - const int rc = check_proxy_connection (); + const int rc = (int) check_proxy_connection (); if (rc == -1) error (); else { @@ -436,7 +436,7 @@ void zmq::socks_connecter_t::close () const int rc = ::close (s); errno_assert (rc == 0); #endif - socket->event_closed (endpoint, s); + socket->event_closed (endpoint, (int) s); s = retired_fd; } diff --git a/src/stdint.hpp b/src/stdint.hpp index 70063a00..f08488e9 100644 --- a/src/stdint.hpp +++ b/src/stdint.hpp @@ -59,4 +59,8 @@ typedef unsigned __int64 uint64_t; #endif +#ifndef UINT8_MAX +#define UINT8_MAX 0xFF +#endif + #endif diff --git a/src/stream.cpp b/src/stream.cpp index 8166fe22..2125e346 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -289,14 +289,13 @@ void zmq::stream_t::identify_peer (pipe_t *pipe_) connect_rid.length ()); connect_rid.clear (); outpipes_t::iterator it = outpipes.find (identity); - if (it != outpipes.end ()) - zmq_assert(false); + zmq_assert (it == outpipes.end ()); } else { put_uint32 (buffer + 1, next_rid++); identity = blob_t (buffer, sizeof buffer); memcpy (options.identity, identity.data (), identity.size ()); - options.identity_size = identity.size (); + options.identity_size = (unsigned char) identity.size (); } pipe_->set_identity (identity); // Add the record into output pipes lookup table diff --git a/src/stream_engine.cpp b/src/stream_engine.cpp index 7f322b38..2c7a784a 100644 --- a/src/stream_engine.cpp +++ b/src/stream_engine.cpp @@ -928,7 +928,7 @@ void zmq::stream_engine_t::error (error_reason_t reason) terminator.close(); } zmq_assert (session); - socket->event_disconnected (endpoint, s); + socket->event_disconnected (endpoint, (int) s); session->flush (); session->engine_error (reason); unplug (); diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp index 435a9045..d36a9144 100644 --- a/src/tcp_connecter.cpp +++ b/src/tcp_connecter.cpp @@ -138,7 +138,7 @@ void zmq::tcp_connecter_t::out_event () // Shut the connecter down. terminate (); - socket->event_connected (endpoint, fd); + socket->event_connected (endpoint, (int) fd); } void zmq::tcp_connecter_t::timer_event (int id_) @@ -352,6 +352,6 @@ void zmq::tcp_connecter_t::close () const int rc = ::close (s); errno_assert (rc == 0); #endif - socket->event_closed (endpoint, s); + socket->event_closed (endpoint, (int) s); s = retired_fd; } diff --git a/src/tcp_listener.cpp b/src/tcp_listener.cpp index c1b4ebf0..343da58d 100644 --- a/src/tcp_listener.cpp +++ b/src/tcp_listener.cpp @@ -111,7 +111,7 @@ void zmq::tcp_listener_t::in_event () session->inc_seqnum (); launch_child (session); send_attach (session, engine, false); - socket->event_accepted (endpoint, fd); + socket->event_accepted (endpoint, (int) fd); } void zmq::tcp_listener_t::close () @@ -124,7 +124,7 @@ void zmq::tcp_listener_t::close () int rc = ::close (s); errno_assert (rc == 0); #endif - socket->event_closed (endpoint, s); + socket->event_closed (endpoint, (int) s); s = retired_fd; } @@ -239,7 +239,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_) goto error; #endif - socket->event_listening (endpoint, s); + socket->event_listening (endpoint, (int) s); return 0; error: diff --git a/src/zmq_utils.cpp b/src/zmq_utils.cpp index 3b79deab..59efc8cf 100644 --- a/src/zmq_utils.cpp +++ b/src/zmq_utils.cpp @@ -155,7 +155,7 @@ uint8_t *zmq_z85_decode (uint8_t *dest, const char *string) } unsigned int byte_nbr = 0; unsigned int char_nbr = 0; - unsigned int string_len = strlen (string); + size_t string_len = strlen (string); uint32_t value = 0; while (char_nbr < string_len) { // Accumulate value in base 85 From c2dcc8060293fd5480219b0afaf5833a93afc8ba Mon Sep 17 00:00:00 2001 From: somdoron Date: Sat, 25 Apr 2015 23:21:27 +0300 Subject: [PATCH 06/19] change minimum version to windows vista and implement dummy condition variable for lower versions --- builds/cmake/platform.hpp.in | 10 --------- builds/mingw32/platform.hpp | 9 -------- builds/msvc/platform.hpp | 8 ------- src/condition_variable.hpp | 43 ++++++++++++++++++++++++++++++++++++ src/windows.hpp | 4 ++-- 5 files changed, 45 insertions(+), 29 deletions(-) diff --git a/builds/cmake/platform.hpp.in b/builds/cmake/platform.hpp.in index b1039dea..21930c42 100644 --- a/builds/cmake/platform.hpp.in +++ b/builds/cmake/platform.hpp.in @@ -86,14 +86,4 @@ #cmakedefine ZMQ_HAVE_WINDOWS -#ifdef ZMQ_HAVE_WINDOWS - #if defined _WIN32_WINNT && _WIN32_WINNT < 0x0600 - #undef _WIN32_WINNT - #endif - - #ifndef _WIN32_WINNT - #define _WIN32_WINNT 0x0600 - #endif -#endif - #endif \ No newline at end of file diff --git a/builds/mingw32/platform.hpp b/builds/mingw32/platform.hpp index 62d36c1f..4af872cd 100644 --- a/builds/mingw32/platform.hpp +++ b/builds/mingw32/platform.hpp @@ -29,13 +29,4 @@ #define ZMQ_HAVE_WINDOWS -#if defined _WIN32_WINNT && _WIN32_WINNT < 0x0600 - #undef _WIN32_WINNT -#endif - -#ifndef _WIN32_WINNT - #define _WIN32_WINNT 0x0600 -#endif - - #endif diff --git a/builds/msvc/platform.hpp b/builds/msvc/platform.hpp index d6e0ce60..4af872cd 100644 --- a/builds/msvc/platform.hpp +++ b/builds/msvc/platform.hpp @@ -29,12 +29,4 @@ #define ZMQ_HAVE_WINDOWS -#if defined _WIN32_WINNT && _WIN32_WINNT < 0x0600 - #undef _WIN32_WINNT -#endif - -#ifndef _WIN32_WINNT - #define _WIN32_WINNT 0x0600 -#endif - #endif diff --git a/src/condition_variable.hpp b/src/condition_variable.hpp index e6c6c52b..fbcad36a 100644 --- a/src/condition_variable.hpp +++ b/src/condition_variable.hpp @@ -31,6 +31,47 @@ #include "windows.hpp" +// Condition variable is supported from Windows Vista only, to use condition variable define _WIN32_WINNT to 0x0600 +#if _WIN32_WINNT < 0x0600 + +namespace zmq +{ + + class condition_variable_t + { + public: + inline condition_variable_t () + { + zmq_assert(false); + } + + inline ~condition_variable_t () + { + + } + + inline int wait (mutex_t* mutex_, int timeout_ ) + { + zmq_assert(false); + return -1; + } + + inline void broadcast () + { + zmq_assert(false); + } + + private: + + // Disable copy construction and assignment. + condition_variable_t (const condition_variable_t&); + void operator = (const condition_variable_t&); + }; + +} + +#else + namespace zmq { @@ -79,6 +120,8 @@ namespace zmq } +#endif + #else #include diff --git a/src/windows.hpp b/src/windows.hpp index eeb05fd1..39a52698 100644 --- a/src/windows.hpp +++ b/src/windows.hpp @@ -27,9 +27,9 @@ #define NOMINMAX // Macros min(a,b) and max(a,b) #endif -// Set target version to Windows Server 2003, Windows XP/SP1 or higher. +// Set target version to Windows Server 2008, Windows Vista or higher. Windows XP (0x0501) is also supported but without client & server socket types. #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0501 +#define _WIN32_WINNT 0x0600 #endif #ifdef __MINGW32__ From 09a65c55989111103a525da0c5f05897dfe99645 Mon Sep 17 00:00:00 2001 From: Martin Hurton Date: Tue, 28 Apr 2015 07:40:31 +0200 Subject: [PATCH 07/19] push: Don't delay pipe termination --- src/push.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/push.cpp b/src/push.cpp index 4da95821..d2531044 100644 --- a/src/push.cpp +++ b/src/push.cpp @@ -36,6 +36,9 @@ void zmq::push_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) { // subscribe_to_all_ is unused (void)subscribe_to_all_; + // Don't delay pipe termination as there is no one + // to receive the delimiter. + pipe_->set_nodelay (); zmq_assert (pipe_); lb.attach (pipe_); From 2e06737bf4b85fbb2d9d085566b48f02e0208798 Mon Sep 17 00:00:00 2001 From: Martin Hurton Date: Tue, 28 Apr 2015 07:44:22 +0200 Subject: [PATCH 08/19] pub: Don't delay pipe termination --- src/pub.cpp | 13 +++++++++++++ src/pub.hpp | 1 + 2 files changed, 14 insertions(+) diff --git a/src/pub.cpp b/src/pub.cpp index fd671882..7895fb86 100644 --- a/src/pub.cpp +++ b/src/pub.cpp @@ -18,6 +18,8 @@ */ #include "pub.hpp" +#include "pipe.hpp" +#include "err.hpp" #include "msg.hpp" zmq::pub_t::pub_t (class ctx_t *parent_, uint32_t tid_, int sid_) : @@ -30,6 +32,17 @@ zmq::pub_t::~pub_t () { } +void zmq::pub_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_) +{ + zmq_assert (pipe_); + + // Don't delay pipe termination as there is no one + // to receive the delimiter. + pipe_->set_nodelay (); + + xpub_t::xattach_pipe (pipe_, subscribe_to_all_); +} + int zmq::pub_t::xrecv (class msg_t *) { // Messages cannot be received from PUB socket. diff --git a/src/pub.hpp b/src/pub.hpp index 21f1e304..f5359f0b 100644 --- a/src/pub.hpp +++ b/src/pub.hpp @@ -38,6 +38,7 @@ namespace zmq ~pub_t (); // Implementations of virtual functions from socket_base_t. + void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_ = false); int xrecv (zmq::msg_t *msg_); bool xhas_in (); From 7e8ba0ecff4c26492a5560acef4473e22600fec5 Mon Sep 17 00:00:00 2001 From: Constantin Rack Date: Tue, 28 Apr 2015 10:42:56 +0200 Subject: [PATCH 09/19] Solution: Build libsodium from latest master branch. Fixes 1386. --- builds/qt-android/build.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/builds/qt-android/build.sh b/builds/qt-android/build.sh index 8f2c19f3..3d4e6057 100755 --- a/builds/qt-android/build.sh +++ b/builds/qt-android/build.sh @@ -26,15 +26,11 @@ if [[ $ANDROID_BUILD_CLEAN ]]; then fi ## -# Build libsodium from latest release tarball +# Build libsodium from latest master branch (android_build_verify_so "libsodium.so" &> /dev/null) || { rm -rf "${cache}/libsodium" - (cd "${cache}" && mkdir libsodium \ - && wget https://download.libsodium.org/libsodium/releases/LATEST.tar.gz\ - -O "${cache}/libsodium.tar.gz" \ - && tar -C libsodium -xf libsodium.tar.gz --strip=1) || exit 1 - + (cd "${cache}" && git clone git://github.com/jedisct1/libsodium.git) || exit 1 (cd "${cache}/libsodium" && ./autogen.sh \ && ./configure "${ANDROID_BUILD_OPTS[@]}" --disable-soname-versions \ && make \ From 7b9e9b838d2868c7fd4db47c09e23d831dc27925 Mon Sep 17 00:00:00 2001 From: Rik van der Heijden Date: Fri, 24 Apr 2015 23:01:20 +0200 Subject: [PATCH 10/19] Issue #1382: Do not send data to backend when there are no listeners (+ tests) --- .gitignore | 1 + AUTHORS | 1 + Makefile.am | 1 + src/proxy.cpp | 6 +- tests/CMakeLists.txt | 1 + tests/test_proxy_terminate.cpp | 113 +++++++++++++++++++++++++++++++++ 6 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 tests/test_proxy_terminate.cpp diff --git a/.gitignore b/.gitignore index fee8796f..a5d4fc07 100644 --- a/.gitignore +++ b/.gitignore @@ -74,6 +74,7 @@ test_linger test_security_null test_security_plain test_proxy +test_proxy_terminate test_abstract_ipc test_filter_ipc test_connect_delay_tipc diff --git a/AUTHORS b/AUTHORS index 8402d31b..0b7d7fc5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -86,6 +86,7 @@ Philip Kovacs Pieter Hintjens Piotr Trojanek Richard Newton +Rik van der Heijden Robert G. Jakabosky Sebastian Otaegui Stefan Radomski diff --git a/Makefile.am b/Makefile.am index e63749ad..aa1c8f1a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -340,6 +340,7 @@ test_apps = \ tests/test_inproc_connect \ tests/test_issue_566 \ tests/test_proxy \ + tests/test_proxy_terminate \ tests/test_many_sockets \ tests/test_ipc_wildcard \ tests/test_diffserv \ diff --git a/src/proxy.cpp b/src/proxy.cpp index 81d98838..de0f045a 100644 --- a/src/proxy.cpp +++ b/src/proxy.cpp @@ -159,14 +159,16 @@ int zmq::proxy ( } // Process a request if (state == active - && items [0].revents & ZMQ_POLLIN) { + && items [0].revents & ZMQ_POLLIN + && items [1].revents & ZMQ_POLLOUT) { rc = forward(frontend_, backend_, capture_,msg); if (unlikely (rc < 0)) return -1; } // Process a reply if (state == active - && items [1].revents & ZMQ_POLLIN) { + && items [1].revents & ZMQ_POLLIN + && items [0].revents & ZMQ_POLLOUT) { rc = forward(backend_, frontend_, capture_,msg); if (unlikely (rc < 0)) return -1; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 74071a04..3daa8164 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -55,6 +55,7 @@ if(NOT WIN32) test_reqrep_ipc test_abstract_ipc test_proxy + test_proxy_terminate test_filter_ipc ) if(HAVE_FORK) diff --git a/tests/test_proxy_terminate.cpp b/tests/test_proxy_terminate.cpp new file mode 100644 index 00000000..83e70d4b --- /dev/null +++ b/tests/test_proxy_terminate.cpp @@ -0,0 +1,113 @@ +/* + Copyright (c) 2007-2015 Contributors as noted in the AUTHORS file + + This file is part of 0MQ. + + 0MQ is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + 0MQ is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#include "testutil.hpp" +#include "../include/zmq_utils.h" + +// This is a test for issue #1382. The server thread creates a SUB-PUSH +// steerable proxy. The main process then sends messages to the SUB +// but there is no pull on the other side, previously the proxy blocks +// in writing to the backend, preventing the proxy from terminating + +void +server_task (void *ctx) +{ + // Frontend socket talks to main process + void *frontend = zmq_socket (ctx, ZMQ_SUB); + assert (frontend); + int rc = zmq_setsockopt (frontend, ZMQ_SUBSCRIBE, "", 0); + assert (rc == 0); + rc = zmq_bind (frontend, "tcp://127.0.0.1:15564"); + assert (rc == 0); + + // Nice socket which is never read + void *backend = zmq_socket (ctx, ZMQ_PUSH); + assert (backend); + rc = zmq_bind (backend, "tcp://127.0.0.1:15563"); + assert (rc == 0); + + // Control socket receives terminate command from main over inproc + void *control = zmq_socket (ctx, ZMQ_SUB); + assert (control); + rc = zmq_setsockopt (control, ZMQ_SUBSCRIBE, "", 0); + assert (rc == 0); + rc = zmq_connect (control, "inproc://control"); + assert (rc == 0); + + // Connect backend to frontend via a proxy + zmq_proxy_steerable (frontend, backend, NULL, control); + + rc = zmq_close (frontend); + assert (rc == 0); + rc = zmq_close (backend); + assert (rc == 0); + rc = zmq_close (control); + assert (rc == 0); +} + + +// The main thread simply starts a basic steerable proxy server, publishes some messages, and then +// waits for the server to terminate. + +int main (void) +{ + setup_test_environment (); + + void *ctx = zmq_ctx_new (); + assert (ctx); + // Control socket receives terminate command from main over inproc + void *control = zmq_socket (ctx, ZMQ_PUB); + assert (control); + int rc = zmq_bind (control, "inproc://control"); + assert (rc == 0); + + void *thread = zmq_threadstart(&server_task, ctx); + msleep (500); // Run for 500 ms + + // Start a secondary publisher which writes data to the SUB-PUSH server socket + void *publisher = zmq_socket (ctx, ZMQ_PUB); + assert (publisher); + rc = zmq_connect (publisher, "tcp://127.0.0.1:15564"); + assert (rc == 0); + + msleep (50); + rc = zmq_send (publisher, "This is a test", 14, 0); + assert (rc == 14); + + msleep (50); + rc = zmq_send (publisher, "This is a test", 14, 0); + assert (rc == 14); + + msleep (50); + rc = zmq_send (publisher, "This is a test", 14, 0); + assert (rc == 14); + rc = zmq_send (control, "TERMINATE", 9, 0); + assert (rc == 9); + + rc = zmq_close (publisher); + assert (rc == 0); + rc = zmq_close (control); + assert (rc == 0); + + zmq_threadclose (thread); + + rc = zmq_ctx_term (ctx); + assert (rc == 0); + return 0; +} From 74888769d664cb447bcff00298b6f74861afd9e1 Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Fri, 1 May 2015 11:31:45 +0200 Subject: [PATCH 11/19] Problem: incomplete specs for test_proxy_terminate Solution: fixed this in Makefile.am --- Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile.am b/Makefile.am index aa1c8f1a..3efd488c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -494,6 +494,9 @@ tests_test_issue_566_LDADD = src/libzmq.la tests_test_proxy_SOURCES = tests/test_proxy.cpp tests_test_proxy_LDADD = src/libzmq.la +tests_test_proxy_terminate_SOURCES = tests/test_proxy_terminate.cpp +tests_test_proxy_terminate_LDADD = src/libzmq.la + tests_test_many_sockets_SOURCES = tests/test_many_sockets.cpp tests_test_many_sockets_LDADD = src/libzmq.la From 095741cd9c7c623a62766edc8897c85462160d73 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 2 May 2015 01:11:54 +1000 Subject: [PATCH 12/19] set FD_SETSIZE to 1024 on mingw Sets FD_SETSIZE to 1024 under mingw systems, increasing it from the default of 64, and brings it into line with the previous limit for CMake builds on mingw. --- configure.ac | 3 +++ 1 file changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index 277811e7..67dd3409 100644 --- a/configure.ac +++ b/configure.ac @@ -265,6 +265,9 @@ case "${host_os}" in if test "x$enable_static" = "xyes"; then AC_MSG_ERROR([Building static libraries is not supported under MinGW32]) fi + + # Additional for windows to set FD_SETSIZE to a larger number + CPPFLAGS=" -DFD_SETSIZE=1024 $CPPFLAGS" ;; *cygwin*) # Define on Cygwin to enable all library features From bd795d6f7a7c6c4ad95fc19b975c20ed962abc26 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 2 May 2015 01:12:22 +1000 Subject: [PATCH 13/19] Update configure.ac --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 67dd3409..d056ea3d 100644 --- a/configure.ac +++ b/configure.ac @@ -266,8 +266,8 @@ case "${host_os}" in AC_MSG_ERROR([Building static libraries is not supported under MinGW32]) fi - # Additional for windows to set FD_SETSIZE to a larger number - CPPFLAGS=" -DFD_SETSIZE=1024 $CPPFLAGS" + # Additional for windows to set FD_SETSIZE to a larger number + CPPFLAGS=" -DFD_SETSIZE=1024 $CPPFLAGS" ;; *cygwin*) # Define on Cygwin to enable all library features From 166a14c4a507b7173a12300bd49ab7385dc39009 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 2 May 2015 01:13:33 +1000 Subject: [PATCH 14/19] Update configure.ac --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index d056ea3d..9f491b73 100644 --- a/configure.ac +++ b/configure.ac @@ -266,7 +266,7 @@ case "${host_os}" in AC_MSG_ERROR([Building static libraries is not supported under MinGW32]) fi - # Additional for windows to set FD_SETSIZE to a larger number + # Set FD_SETSIZE to 1024 CPPFLAGS=" -DFD_SETSIZE=1024 $CPPFLAGS" ;; *cygwin*) From f0a76318f420e591a6ea4600c7310d22253cb450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20S=2E=20Ga=C3=9Fmann?= Date: Tue, 5 May 2015 21:39:50 +0200 Subject: [PATCH 15/19] REPLACE MSVC VERSION SUFFIX VARIABLE Replace _zmq_COMPILER with CMAKE_VS_PLATFORM_TOOLSET; so the suffix can be automagically generated for every MSVC compiler supported by cmake. --- CMakeLists.txt | 14 +++++++------- builds/cmake/Modules/TestZMQVersion.cmake | 10 ---------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f23f0e4..5247f383 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -294,8 +294,8 @@ if(MSVC) set(OPENPGM_INCLUDE_DIRS ${OPENPGM_ROOT}/include) set(OPENPGM_LIBRARY_DIRS ${OPENPGM_ROOT}/lib) set(OPENPGM_LIBRARIES - optimized libpgm${_zmq_COMPILER}-mt-${OPENPGM_VERSION_MAJOR}_${OPENPGM_VERSION_MINOR}_${OPENPGM_VERSION_MICRO}.lib - debug libpgm${_zmq_COMPILER}-mt-gd-${OPENPGM_VERSION_MAJOR}_${OPENPGM_VERSION_MINOR}_${OPENPGM_VERSION_MICRO}.lib) + optimized libpgm-${CMAKE_VS_PLATFORM_TOOLSET}-mt-${OPENPGM_VERSION_MAJOR}_${OPENPGM_VERSION_MINOR}_${OPENPGM_VERSION_MICRO}.lib + debug libpgm-${CMAKE_VS_PLATFORM_TOOLSET}-mt-gd-${OPENPGM_VERSION_MAJOR}_${OPENPGM_VERSION_MINOR}_${OPENPGM_VERSION_MICRO}.lib) endif() else() if(WITH_OPENPGM) @@ -578,15 +578,15 @@ if(MSVC) target_link_libraries(libzmq ${OPTIONAL_LIBRARIES}) set_target_properties(libzmq PROPERTIES PUBLIC_HEADER "${public_headers}" - RELEASE_POSTFIX "${_zmq_COMPILER}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}" - DEBUG_POSTFIX "${_zmq_COMPILER}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}" + RELEASE_POSTFIX "-${CMAKE_VS_PLATFORM_TOOLSET}-mt-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}" + DEBUG_POSTFIX "-${CMAKE_VS_PLATFORM_TOOLSET}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin" COMPILE_DEFINITIONS "DLL_EXPORT") add_library(libzmq-static STATIC ${sources}) set_target_properties(libzmq-static PROPERTIES PUBLIC_HEADER "${public_headers}" - RELEASE_POSTFIX "${_zmq_COMPILER}-mt-s-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}" - DEBUG_POSTFIX "${_zmq_COMPILER}-mt-sgd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}" + RELEASE_POSTFIX "-${CMAKE_VS_PLATFORM_TOOLSET}-mt-s-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}" + DEBUG_POSTFIX "-${CMAKE_VS_PLATFORM_TOOLSET}-mt-sgd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}" COMPILE_FLAGS "/D ZMQ_STATIC" OUTPUT_NAME "libzmq") else() @@ -698,7 +698,7 @@ if(MSVC) ARCHIVE DESTINATION lib PUBLIC_HEADER DESTINATION include COMPONENT SDK) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bin/libzmq${_zmq_COMPILER}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}.pdb DESTINATION lib + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/bin/libzmq-${CMAKE_VS_PLATFORM_TOOLSET}-mt-gd-${ZMQ_VERSION_MAJOR}_${ZMQ_VERSION_MINOR}_${ZMQ_VERSION_PATCH}.pdb DESTINATION lib COMPONENT SDK) else() install(TARGETS libzmq diff --git a/builds/cmake/Modules/TestZMQVersion.cmake b/builds/cmake/Modules/TestZMQVersion.cmake index 130c6013..49a3f309 100644 --- a/builds/cmake/Modules/TestZMQVersion.cmake +++ b/builds/cmake/Modules/TestZMQVersion.cmake @@ -6,13 +6,3 @@ string(REGEX REPLACE ".*#define ZMQ_VERSION_PATCH ([0-9]+).*" "\\1" ZMQ_VERSION_ set(ZMQ_VERSION "${ZMQ_VERSION_MAJOR}.${ZMQ_VERSION_MINOR}.${ZMQ_VERSION_PATCH}") message(STATUS "Detected ZMQ Version - ${ZMQ_VERSION}") - -if(MSVC_VERSION MATCHES "1700") - set(_zmq_COMPILER "-v110") -elseif(MSVC10) - set(_zmq_COMPILER "-v100") -elseif(MSVC90) - set(_zmq_COMPILER "-v90") -else() - set(_zmq_COMPILER "") -endif() From 5f9b2582957c1f46453e39b00afa21ae6822c936 Mon Sep 17 00:00:00 2001 From: Anton Sergeev Date: Wed, 6 May 2015 21:25:26 +0600 Subject: [PATCH 16/19] Make CMake option for perf-tools This allow disable making perf-tools in Release build type Signed-off-by: Anton Sergeev --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5247f383..1a3877fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -648,6 +648,12 @@ set(perf-tools local_lat inproc_thr) if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") # Why? +option(WITH_PERF_TOOL "Build with perf-tools" ON) +else() +option(WITH_PERF_TOOL "Build with perf-tools" OFF) +endif() + +if(WITH_PERF_TOOL) foreach(perf-tool ${perf-tools}) add_executable(${perf-tool} perf/${perf-tool}.cpp) target_link_libraries(${perf-tool} libzmq) From f4f918ba73dcd1b0de17393f98fabb699ac8ade8 Mon Sep 17 00:00:00 2001 From: Dan Riegsecker <1baldgeek@gmail.com> Date: Thu, 7 May 2015 16:52:37 -0400 Subject: [PATCH 17/19] Some test fail to build targeting less that Windows Vista When targeting a version of Windows less than Windows Vista, the security tests fail to build. Added a check for Windows version and substituted inet_pton for inet_addr. Fixes libzmq issue #1396. --- tests/test_security_curve.cpp | 6 +++++- tests/test_security_null.cpp | 4 ++++ tests/test_security_plain.cpp | 6 +++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tests/test_security_curve.cpp b/tests/test_security_curve.cpp index 854f4f94..b8c7b2b0 100644 --- a/tests/test_security_curve.cpp +++ b/tests/test_security_curve.cpp @@ -235,7 +235,11 @@ int main (void) ip4addr.sin_family = AF_INET; ip4addr.sin_port = htons (9998); - inet_pton (AF_INET, "127.0.0.1", &ip4addr.sin_addr); +#if (_WIN32_WINNT < 0x0600) + ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1"); +#else + inet_pton(AF_INET, "127.0.0.1", &ip4addr.sin_addr); +#endif s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); rc = connect (s, (struct sockaddr*) &ip4addr, sizeof (ip4addr)); diff --git a/tests/test_security_null.cpp b/tests/test_security_null.cpp index 25ab74f4..d3b212a1 100644 --- a/tests/test_security_null.cpp +++ b/tests/test_security_null.cpp @@ -148,7 +148,11 @@ int main (void) ip4addr.sin_family = AF_INET; ip4addr.sin_port = htons(9003); +#if (_WIN32_WINNT < 0x0600) + ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1"); +#else inet_pton(AF_INET, "127.0.0.1", &ip4addr.sin_addr); +#endif s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); rc = connect (s, (struct sockaddr*) &ip4addr, sizeof ip4addr); diff --git a/tests/test_security_plain.cpp b/tests/test_security_plain.cpp index 909dc290..8bae0932 100644 --- a/tests/test_security_plain.cpp +++ b/tests/test_security_plain.cpp @@ -154,7 +154,11 @@ int main (void) ip4addr.sin_family = AF_INET; ip4addr.sin_port = htons (9998); - inet_pton (AF_INET, "127.0.0.1", &ip4addr.sin_addr); +#if (_WIN32_WINNT < 0x0600) + ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1"); +#else + inet_pton(AF_INET, "127.0.0.1", &ip4addr.sin_addr); +#endif s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); rc = connect (s, (struct sockaddr*) &ip4addr, sizeof (ip4addr)); From e89577d30c278fba0f9e40266ceb6fb2821907d5 Mon Sep 17 00:00:00 2001 From: Peter Korsgaard Date: Wed, 13 May 2015 08:01:34 +0200 Subject: [PATCH 18/19] libzmq: Fix pkg-config files for static linking Libzmq uses C++ standard library features, so users of it should link against that as well when statically linking. Add it to Libs.private so users using pkg-config automatically gets the correct linker flags. Signed-off-by: Peter Korsgaard --- src/libzmq.pc.cmake.in | 1 + src/libzmq.pc.in | 1 + 2 files changed, 2 insertions(+) diff --git a/src/libzmq.pc.cmake.in b/src/libzmq.pc.cmake.in index 4f57939d..e11685d1 100644 --- a/src/libzmq.pc.cmake.in +++ b/src/libzmq.pc.cmake.in @@ -7,4 +7,5 @@ Name: libzmq Description: 0MQ c++ library Version: @ZMQ_VERSION_MAJOR@.@ZMQ_VERSION_MINOR@.@ZMQ_VERSION_PATCH@ Libs: -L${libdir} -lzmq +Libs.private: -lstdc++ Cflags: -I${includedir} diff --git a/src/libzmq.pc.in b/src/libzmq.pc.in index ba155a38..52a39f72 100644 --- a/src/libzmq.pc.in +++ b/src/libzmq.pc.in @@ -7,4 +7,5 @@ Name: libzmq Description: 0MQ c++ library Version: @VERSION@ Libs: -L${libdir} -lzmq +Libs.private: -lstdc++ Cflags: -I${includedir} From 537626258f699f1ffc543a5b1f37c55236ef494c Mon Sep 17 00:00:00 2001 From: Brian Knox Date: Tue, 19 May 2015 09:38:53 -0400 Subject: [PATCH 19/19] remove temp printf from stream_engine --- src/stream_engine.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/stream_engine.cpp b/src/stream_engine.cpp index 2c7a784a..2cd02f69 100644 --- a/src/stream_engine.cpp +++ b/src/stream_engine.cpp @@ -668,18 +668,6 @@ bool zmq::stream_engine_t::handshake () } #endif else { - // Temporary support for security debugging - char mechanism [21]; - memcpy (mechanism, greeting_recv + 12, 20); - mechanism [20] = 0; - printf ("LIBZMQ I: security failure, self=%s peer=%s\n", - options.mechanism == ZMQ_NULL? "NULL": - options.mechanism == ZMQ_PLAIN? "PLAIN": - options.mechanism == ZMQ_CURVE? "CURVE": - options.mechanism == ZMQ_GSSAPI? "GSSAPI": - "OTHER", - mechanism); - error (protocol_error); return false; }