handle decoding malformed messages

Signed-off-by: Dhammika Pathirana <dhammika@gmail.com>
This commit is contained in:
Dhammika Pathirana
2010-10-23 20:59:54 +02:00
committed by Martin Sustrik
parent 8d6979922e
commit 71bef330fc
3 changed files with 53 additions and 22 deletions

View File

@@ -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;