From 06bdf2c4f96a6324b3fe667cebb03d44cd100a73 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Fri, 16 Sep 2011 09:29:43 +0200 Subject: 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 --- src/req.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/req.cpp') diff --git a/src/req.cpp b/src/req.cpp index 323e058..04a19fb 100644 --- a/src/req.cpp +++ b/src/req.cpp @@ -158,3 +158,23 @@ zmq::req_session_t::~req_session_t () { } +int zmq::req_session_t::write (msg_t *msg_) +{ + if (state == request_id) { + if (msg_->flags () == msg_t::label && msg_->size () == 4) { + state = body; + return xreq_session_t::write (msg_); + } + } + else { + if (msg_->flags () == msg_t::more) + return xreq_session_t::write (msg_); + if (msg_->flags () == 0) { + state = request_id; + return xreq_session_t::write (msg_); + } + } + errno = EFAULT; + return -1; +} + -- cgit v1.2.3