Commit da1ef4d2 authored by Pieter Hintjens's avatar Pieter Hintjens Committed by Martin Sustrik

Fixed REP assert on missing envelope

Signed-off-by: 's avatarPieter Hintjens <ph@imatix.com>
parent 0c5b781e
...@@ -67,24 +67,38 @@ int zmq::rep_t::xrecv (msg_t *msg_, int flags_) ...@@ -67,24 +67,38 @@ int zmq::rep_t::xrecv (msg_t *msg_, int flags_)
if (request_begins) { if (request_begins) {
// Copy the backtrace stack to the reply pipe. // Copy the backtrace stack to the reply pipe.
bool bottom = false; while (true) {
while (!bottom) {
// TODO: What if request can be read but reply pipe is not // TODO: If request can be read but reply pipe is not
// ready for writing? // ready for writing, we should drop the reply.
// Get next part of the backtrace stack. // Get next part of the backtrace stack.
int rc = xrep_t::xrecv (msg_, flags_); int rc = xrep_t::xrecv (msg_, flags_);
if (rc != 0) if (rc != 0)
return rc; return rc;
zmq_assert (msg_->flags () & msg_t::more);
if (msg_->flags () & msg_t::more) {
// Empty message part delimits the traceback stack. // Empty message part delimits the traceback stack.
bottom = (msg_->size () == 0); bool bottom = (msg_->size () == 0);
// Push it to the reply pipe. // Push it to the reply pipe.
rc = xrep_t::xsend (msg_, flags_); rc = xrep_t::xsend (msg_, flags_);
zmq_assert (rc == 0); zmq_assert (rc == 0);
// The end of the traceback, move to processing message body.
if (bottom)
break;
}
else {
// If the traceback stack is malformed, discard anything
// already sent to pipe (we're at end of invalid message)
// and continue reading -- that'll switch us to the next pipe
// and next request.
rc = xrep_t::rollback ();
zmq_assert (rc == 0);
}
} }
request_begins = false; request_begins = false;
......
...@@ -289,6 +289,17 @@ int zmq::xrep_t::xrecv (msg_t *msg_, int flags_) ...@@ -289,6 +289,17 @@ int zmq::xrep_t::xrecv (msg_t *msg_, int flags_)
return -1; return -1;
} }
int zmq::xrep_t::rollback (void)
{
if (current_out) {
current_out->rollback ();
current_out = NULL;
more_out = false;
}
return 0;
}
bool zmq::xrep_t::xhas_in () bool zmq::xrep_t::xhas_in ()
{ {
// There are subsequent parts of the partly-read message available. // There are subsequent parts of the partly-read message available.
......
...@@ -51,6 +51,11 @@ namespace zmq ...@@ -51,6 +51,11 @@ namespace zmq
bool xhas_in (); bool xhas_in ();
bool xhas_out (); bool xhas_out ();
protected:
// Rollback any message parts that were sent but not yet flushed.
int rollback ();
private: private:
// Hook into the termination process. // Hook into the termination process.
......
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