Skip to content

Commit

Permalink
Merge pull request #487 from miniway/master
Browse files Browse the repository at this point in the history
returns -1 with EAGAIN when mandatory is set and pipe is full
  • Loading branch information
hintjens committed Dec 11, 2012
2 parents 2a7b219 + a0cecc7 commit 4febe88
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions tests/test_router_mandatory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,25 @@ 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);
assert (rc == 1);
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);
Expand Down

0 comments on commit 4febe88

Please sign in to comment.