summaryrefslogtreecommitdiff
path: root/src/rep.cpp
diff options
context:
space:
mode:
authorPieter Hintjens <ph@imatix.com>2011-05-08 09:02:47 +0200
committerMartin Sustrik <sustrik@250bpm.com>2011-05-08 09:02:47 +0200
commitda1ef4d2685c02e8320847d49a38726b2b6d52f0 (patch)
treef4b63f141a2a01c6e7a1d4366e678e15820ae5de /src/rep.cpp
parent0c5b781e97f2bea42925495a5505c51e769fba7f (diff)
Fixed REP assert on missing envelope
Signed-off-by: Pieter Hintjens <ph@imatix.com>
Diffstat (limited to 'src/rep.cpp')
-rw-r--r--src/rep.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/rep.cpp b/src/rep.cpp
index ef0defc..8878bcd 100644
--- a/src/rep.cpp
+++ b/src/rep.cpp
@@ -67,24 +67,38 @@ int zmq::rep_t::xrecv (msg_t *msg_, int flags_)
if (request_begins) {
// Copy the backtrace stack to the reply pipe.
- bool bottom = false;
- while (!bottom) {
+ while (true) {
- // TODO: What if request can be read but reply pipe is not
- // ready for writing?
+ // TODO: If request can be read but reply pipe is not
+ // ready for writing, we should drop the reply.
// Get next part of the backtrace stack.
int rc = xrep_t::xrecv (msg_, flags_);
if (rc != 0)
return rc;
- zmq_assert (msg_->flags () & msg_t::more);
- // Empty message part delimits the traceback stack.
- bottom = (msg_->size () == 0);
+ if (msg_->flags () & msg_t::more) {
- // Push it to the reply pipe.
- rc = xrep_t::xsend (msg_, flags_);
- zmq_assert (rc == 0);
+ // Empty message part delimits the traceback stack.
+ bool bottom = (msg_->size () == 0);
+
+ // Push it to the reply pipe.
+ rc = xrep_t::xsend (msg_, flags_);
+ 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;