Commit 37fd1a77 authored by Martin Hurton's avatar Martin Hurton

Handle full-pipe for REP sockets more gracefully

parent 2f219d7c
...@@ -167,9 +167,6 @@ int zmq::rep_t::xsend (zmq_msg_t *msg_, int flags_) ...@@ -167,9 +167,6 @@ int zmq::rep_t::xsend (zmq_msg_t *msg_, int flags_)
return -1; return -1;
} }
// Check whether it's last part of the reply.
more = msg_->flags & ZMQ_MSG_MORE;
if (reply_pipe) { if (reply_pipe) {
// Push message to the reply pipe. // Push message to the reply pipe.
...@@ -177,8 +174,14 @@ int zmq::rep_t::xsend (zmq_msg_t *msg_, int flags_) ...@@ -177,8 +174,14 @@ int zmq::rep_t::xsend (zmq_msg_t *msg_, int flags_)
zmq_assert (!more || written); zmq_assert (!more || written);
// The pipe is full... // The pipe is full...
// When this happens, we simply return an error.
// This makes REP sockets vulnerable to DoS attack when
// misbehaving requesters stop collecting replies.
// TODO: Tear down the underlying connection (?) // TODO: Tear down the underlying connection (?)
zmq_assert (written); if (!written) {
errno = EAGAIN;
return -1;
}
} }
else { else {
...@@ -186,6 +189,9 @@ int zmq::rep_t::xsend (zmq_msg_t *msg_, int flags_) ...@@ -186,6 +189,9 @@ int zmq::rep_t::xsend (zmq_msg_t *msg_, int flags_)
zmq_msg_close (msg_); zmq_msg_close (msg_);
} }
// Check whether it's last part of the reply.
more = msg_->flags & ZMQ_MSG_MORE;
// Flush the reply to the requester. // Flush the reply to the requester.
if (!more) { if (!more) {
reply_pipe->flush (); reply_pipe->flush ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment