summaryrefslogtreecommitdiff
path: root/src/decoder.hpp
diff options
context:
space:
mode:
authorDhammika Pathirana <dhammika@gmail.com>2010-10-23 20:59:54 +0200
committerMartin Sustrik <sustrik@250bpm.com>2010-10-23 20:59:54 +0200
commit71bef330fc9f09ee070c90d174fc0bcb7783b38d (patch)
tree831702e8b6a3f8ee18f0a738747fe88b4d44bb96 /src/decoder.hpp
parent8d6979922efff7183ce03b49715472e5b2a6a1df (diff)
handle decoding malformed messages
Signed-off-by: Dhammika Pathirana <dhammika@gmail.com>
Diffstat (limited to 'src/decoder.hpp')
-rw-r--r--src/decoder.hpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/decoder.hpp b/src/decoder.hpp
index 87982a0..ab7d454 100644
--- a/src/decoder.hpp
+++ b/src/decoder.hpp
@@ -98,9 +98,13 @@ namespace zmq
read_pos += size_;
to_read -= size_;
- while (!to_read)
- if (!(static_cast <T*> (this)->*next) ())
+ while (!to_read) {
+ if (!(static_cast <T*> (this)->*next) ()) {
+ if (unlikely (!(static_cast <T*> (this)->next)))
+ return (size_t) -1;
return size_;
+ }
+ }
return size_;
}
@@ -109,9 +113,13 @@ namespace zmq
// Try to get more space in the message to fill in.
// If none is available, return.
- while (!to_read)
- if (!(static_cast <T*> (this)->*next) ())
+ while (!to_read) {
+ if (!(static_cast <T*> (this)->*next) ()) {
+ if (unlikely (!(static_cast <T*> (this)->next)))
+ return (size_t) -1;
return pos;
+ }
+ }
// If there are no more data in the buffer, return.
if (pos == size_)
@@ -142,6 +150,13 @@ namespace zmq
next = next_;
}
+ // This function should be called from the derived class to
+ // abort decoder state machine.
+ inline void decoding_error ()
+ {
+ next = NULL;
+ }
+
private:
unsigned char *read_pos;