summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/options.cpp4
-rw-r--r--src/options.hpp8
-rw-r--r--src/pipe.hpp5
-rw-r--r--src/session.cpp2
-rw-r--r--src/socket_base.cpp4
-rw-r--r--src/xrep.cpp4
-rw-r--r--src/xreq.cpp4
7 files changed, 25 insertions, 6 deletions
diff --git a/src/options.cpp b/src/options.cpp
index 80ab294..aa92f93 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -41,7 +41,9 @@ zmq::options_t::options_t () :
filter (1),
rcvtimeo (-1),
sndtimeo (-1),
- immediate_connect (true)
+ immediate_connect (true),
+ delay_on_close (true),
+ delay_on_disconnect (true)
{
}
diff --git a/src/options.hpp b/src/options.hpp
index 858ec2e..70144b2 100644
--- a/src/options.hpp
+++ b/src/options.hpp
@@ -87,6 +87,14 @@ namespace zmq
// is not aware of the peer's identity, however, it is able to send
// messages straight away.
bool immediate_connect;
+
+ // If true, session reads all the pending messages from the pipe and
+ // sends them to the network when socket is closed.
+ bool delay_on_close;
+
+ // If true, socket reads all the messages from the pipe and delivers
+ // them to the user when the peer terminates.
+ bool delay_on_disconnect;
};
}
diff --git a/src/pipe.hpp b/src/pipe.hpp
index df85bc2..437d84d 100644
--- a/src/pipe.hpp
+++ b/src/pipe.hpp
@@ -34,8 +34,9 @@ namespace zmq
// Create a pipepair for bi-directional transfer of messages.
// First HWM is for messages passed from first pipe to the second pipe.
// Second HWM is for messages passed from second pipe to the first pipe.
- // Delay specifies whether the pipe receives all the pending messages
- // before terminating or whether it terminates straight away.
+ // Delay specifies how the pipe behaves when the peer terminates. If true
+ // pipe receives all the pending messages before terminating, otherwise it
+ // terminates straight away.
int pipepair (class object_t *parents_ [2], class pipe_t* pipes_ [2],
int hwms_ [2], bool delays_ [2]);
diff --git a/src/session.cpp b/src/session.cpp
index 334763a..9286054 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -180,7 +180,7 @@ void zmq::session_t::process_attach (i_engine *engine_,
object_t *parents [2] = {this, socket};
pipe_t *pipes [2] = {NULL, NULL};
int hwms [2] = {options.rcvhwm, options.sndhwm};
- bool delays [2] = {true, true};
+ bool delays [2] = {options.delay_on_close, options.delay_on_disconnect};
int rc = pipepair (parents, pipes, hwms, delays);
errno_assert (rc == 0);
diff --git a/src/socket_base.cpp b/src/socket_base.cpp
index 804ec46..74a345b 100644
--- a/src/socket_base.cpp
+++ b/src/socket_base.cpp
@@ -426,7 +426,7 @@ int zmq::socket_base_t::connect (const char *addr_)
object_t *parents [2] = {this, peer.socket};
pipe_t *pipes [2] = {NULL, NULL};
int hwms [2] = {sndhwm, rcvhwm};
- bool delays [2] = {true, true};
+ bool delays [2] = {options.delay_on_disconnect, options.delay_on_close};
int rc = pipepair (parents, pipes, hwms, delays);
errno_assert (rc == 0);
@@ -462,7 +462,7 @@ int zmq::socket_base_t::connect (const char *addr_)
object_t *parents [2] = {this, session};
pipe_t *pipes [2] = {NULL, NULL};
int hwms [2] = {options.sndhwm, options.rcvhwm};
- bool delays [2] = {true, true};
+ bool delays [2] = {options.delay_on_disconnect, options.delay_on_close};
int rc = pipepair (parents, pipes, hwms, delays);
errno_assert (rc == 0);
diff --git a/src/xrep.cpp b/src/xrep.cpp
index 4a474cf..fe9ab52 100644
--- a/src/xrep.cpp
+++ b/src/xrep.cpp
@@ -33,6 +33,10 @@ zmq::xrep_t::xrep_t (class ctx_t *parent_, uint32_t tid_) :
{
options.type = ZMQ_XREP;
+ // If peer disconnect there's noone to send reply to anyway. We can drop
+ // all the outstanding requests from that peer.
+ options.delay_on_disconnect = false;
+
prefetched_msg.init ();
// Start the peer ID sequence from a random point.
diff --git a/src/xreq.cpp b/src/xreq.cpp
index 2371a34..85e2238 100644
--- a/src/xreq.cpp
+++ b/src/xreq.cpp
@@ -26,6 +26,10 @@ zmq::xreq_t::xreq_t (class ctx_t *parent_, uint32_t tid_) :
socket_base_t (parent_, tid_)
{
options.type = ZMQ_XREQ;
+
+ // If the socket is closing we can drop all the outbound requests. There'll
+ // be noone to receive the replies anyway.
+ options.delay_on_close = false;
}
zmq::xreq_t::~xreq_t ()