From 518b939f316510998cb62271ffe3df219d23725f Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Fri, 24 Jul 2015 05:12:11 +0800 Subject: [PATCH 1/3] make ZMQ_STREAM_NOTIFY also control disconnect notificatons --- doc/zmq_setsockopt.txt | 10 +++++----- src/stream_engine.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/zmq_setsockopt.txt b/doc/zmq_setsockopt.txt index 61392959..4ace7910 100644 --- a/doc/zmq_setsockopt.txt +++ b/doc/zmq_setsockopt.txt @@ -716,11 +716,11 @@ Default value:: -1 (infinite) Applicable socket types:: all -ZMQ_STREAM_NOTIFY: send connect notifications -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Enables connect notifications on a STREAM socket, when set to 1. By default a -STREAM socket does not notify new connections. When notifications are enabled, -it delivers a zero-length message to signal new client connections. +ZMQ_STREAM_NOTIFY: send connect and disconnect notifications +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Enables connect and disconnect notifications on a STREAM socket, when set +to 1. When notifications are enabled, the socket delivers a zero-length +message when a peer connects or disconnects. [horizontal] Option value type:: int diff --git a/src/stream_engine.cpp b/src/stream_engine.cpp index 96b6bde6..17c3d52c 100644 --- a/src/stream_engine.cpp +++ b/src/stream_engine.cpp @@ -965,7 +965,7 @@ int zmq::stream_engine_t::write_subscription_msg (msg_t *msg_) void zmq::stream_engine_t::error (error_reason_t reason) { - if (options.raw_socket) { + if (options.raw_socket && options.raw_notify) { // For raw sockets, send a final 0-length message to the application // so that it knows the peer has been disconnected. msg_t terminator; From 3e7d73736093b5e9608ef74890d5f1772b4631fe Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Fri, 24 Jul 2015 05:20:31 +0800 Subject: [PATCH 2/3] change ZMQ_STREAM_NOTIFY to default to 1 --- doc/zmq_setsockopt.txt | 2 +- src/options.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/zmq_setsockopt.txt b/doc/zmq_setsockopt.txt index 4ace7910..1d48f3f8 100644 --- a/doc/zmq_setsockopt.txt +++ b/doc/zmq_setsockopt.txt @@ -725,7 +725,7 @@ message when a peer connects or disconnects. [horizontal] Option value type:: int Option value unit:: 0, 1 -Default value:: 0 +Default value:: 1 Applicable socket types:: ZMQ_STREAM diff --git a/src/options.cpp b/src/options.cpp index da86c3fb..6d4d000d 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -58,7 +58,7 @@ zmq::options_t::options_t () : invert_matching(false), recv_identity (false), raw_socket (false), - raw_notify (false), + raw_notify (true), tcp_keepalive (-1), tcp_keepalive_cnt (-1), tcp_keepalive_idle (-1), From fd51b0e508172ec8b99b0785c4d7ab13e9b5f220 Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Fri, 24 Jul 2015 05:39:47 +0800 Subject: [PATCH 3/3] update test that relied on connect notifications to be disabled --- tests/test_connect_rid.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_connect_rid.cpp b/tests/test_connect_rid.cpp index 0dd24512..7b2c092e 100644 --- a/tests/test_connect_rid.cpp +++ b/tests/test_connect_rid.cpp @@ -36,12 +36,15 @@ void test_stream_2_stream(){ char buff[256]; char msg[] = "hi 1"; const char *bindip = "tcp://127.0.0.1:5556"; + int disabled = 0; int zero = 0; void *ctx = zmq_ctx_new (); // Set up listener STREAM. rbind = zmq_socket (ctx, ZMQ_STREAM); assert (rbind); + ret = zmq_setsockopt (rbind, ZMQ_STREAM_NOTIFY, &disabled, sizeof (disabled)); + assert (ret == 0); ret = zmq_setsockopt (rbind, ZMQ_LINGER, &zero, sizeof (zero)); assert (0 == ret); ret = zmq_bind (rbind, bindip);