returns -1 with EAGAIN when mandatory is set and pipe is full

This commit is contained in:
Min(Dongmin Yu) 2012-12-11 19:41:36 +09:00
parent 2a7b219f07
commit a0cecc718d
2 changed files with 10 additions and 11 deletions

View File

@ -159,21 +159,21 @@ int zmq::router_t::xsend (msg_t *msg_)
// router_mandatory is set. // router_mandatory is set.
blob_t identity ((unsigned char*) msg_->data (), msg_->size ()); blob_t identity ((unsigned char*) msg_->data (), msg_->size ());
outpipes_t::iterator it = outpipes.find (identity); outpipes_t::iterator it = outpipes.find (identity);
bool unreach = false;
if (it != outpipes.end ()) { if (it != outpipes.end ()) {
current_out = it->second.pipe; current_out = it->second.pipe;
if (!current_out->check_write ()) { if (!current_out->check_write ()) {
it->second.active = false; it->second.active = false;
current_out = NULL; current_out = NULL;
unreach = mandatory ? true: false; if (mandatory) {
more_out = false;
errno = EAGAIN;
return -1;
}
} }
} }
else else
if (mandatory) if (mandatory) {
unreach = true;
if (unreach) {
more_out = false; more_out = false;
errno = EHOSTUNREACH; errno = EHOSTUNREACH;
return -1; return -1;

View File

@ -79,18 +79,17 @@ int main (void)
rc = zmq_send (sa, "DATA1", 5, 0); rc = zmq_send (sa, "DATA1", 5, 0);
assert (rc == 5); assert (rc == 5);
rc = zmq_send (sa, "X", 1, ZMQ_SNDMORE | ZMQ_DONTWAIT);
rc = zmq_send (sa, "X", 1, ZMQ_SNDMORE);
if (rc == 1) { if (rc == 1) {
// the first frame has been sent // the first frame has been sent
rc = zmq_send (sa, "DATA2", 5, 0); rc = zmq_send (sa, "DATA2", 5, 0);
assert (rc == 5); assert (rc == 5);
// send more // 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); rc = zmq_close (sa);