From a0cecc718d3d95279dcc7b0d9b6c1d09fb4cfd97 Mon Sep 17 00:00:00 2001 From: "Min(Dongmin Yu)" Date: Tue, 11 Dec 2012 19:41:36 +0900 Subject: [PATCH] returns -1 with EAGAIN when mandatory is set and pipe is full --- src/router.cpp | 12 ++++++------ tests/test_router_mandatory.cpp | 9 ++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/router.cpp b/src/router.cpp index 6e578509..3133e992 100644 --- a/src/router.cpp +++ b/src/router.cpp @@ -159,21 +159,21 @@ int zmq::router_t::xsend (msg_t *msg_) // router_mandatory is set. blob_t identity ((unsigned char*) msg_->data (), msg_->size ()); outpipes_t::iterator it = outpipes.find (identity); - bool unreach = false; if (it != outpipes.end ()) { current_out = it->second.pipe; if (!current_out->check_write ()) { it->second.active = false; current_out = NULL; - unreach = mandatory ? true: false; + if (mandatory) { + more_out = false; + errno = EAGAIN; + return -1; + } } } else - if (mandatory) - unreach = true; - - if (unreach) { + if (mandatory) { more_out = false; errno = EHOSTUNREACH; return -1; diff --git a/tests/test_router_mandatory.cpp b/tests/test_router_mandatory.cpp index 321d8a3b..1bbfe2b6 100644 --- a/tests/test_router_mandatory.cpp +++ b/tests/test_router_mandatory.cpp @@ -71,7 +71,7 @@ int main (void) assert (rc == 0); // wait until connect - zmq_sleep (1); + zmq_sleep (1); // make it full and check that it fails rc = zmq_send (sa, "X", 1, ZMQ_SNDMORE); @@ -79,18 +79,17 @@ int main (void) rc = zmq_send (sa, "DATA1", 5, 0); assert (rc == 5); - - rc = zmq_send (sa, "X", 1, ZMQ_SNDMORE); + rc = zmq_send (sa, "X", 1, ZMQ_SNDMORE | ZMQ_DONTWAIT); if (rc == 1) { // the first frame has been sent rc = zmq_send (sa, "DATA2", 5, 0); assert (rc == 5); // send more - rc = zmq_send (sa, "X", 1, ZMQ_SNDMORE); + rc = zmq_send (sa, "X", 1, ZMQ_SNDMORE | ZMQ_DONTWAIT); } - assert (rc == -1 && errno == EHOSTUNREACH); + assert (rc == -1 && errno == EAGAIN); rc = zmq_close (sa);