summaryrefslogtreecommitdiff
path: root/src/encoder.cpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2011-09-16 09:29:43 +0200
committerMartin Sustrik <sustrik@250bpm.com>2011-09-16 09:29:43 +0200
commit06bdf2c4f96a6324b3fe667cebb03d44cd100a73 (patch)
treee7678e0f861ae538fe03c75484d708042f62659d /src/encoder.cpp
parentf78d9b6bfca13e298c29fadabbbc870b37a0a573 (diff)
Check message syntax in REQ asynchronously
This patch adds support for checking messages as they arrive (as opposed to when they are recv'd by the user) and drop the connection if they are malformed. It also uses this new feature to check for validity of inbound messages in REQ socket. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src/encoder.cpp')
-rw-r--r--src/encoder.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/encoder.cpp b/src/encoder.cpp
index 6d09384..8689e45 100644
--- a/src/encoder.cpp
+++ b/src/encoder.cpp
@@ -20,6 +20,7 @@
#include "encoder.hpp"
#include "session_base.hpp"
+#include "likely.hpp"
#include "wire.hpp"
zmq::encoder_t::encoder_t (size_t bufsize_) :
@@ -62,7 +63,14 @@ bool zmq::encoder_t::message_ready ()
// Note that new state is set only if write is successful. That way
// unsuccessful write will cause retry on the next state machine
// invocation.
- if (!session || !session->read (&in_progress)) {
+ if (unlikely (!session)) {
+ rc = in_progress.init ();
+ errno_assert (rc == 0);
+ return false;
+ }
+ rc = session->read (&in_progress);
+ if (unlikely (rc != 0)) {
+ errno_assert (errno == EAGAIN);
rc = in_progress.init ();
errno_assert (rc == 0);
return false;