summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Hurton <hurtonm@gmail.com>2012-05-08 09:28:17 +0200
committerMartin Sustrik <sustrik@250bpm.com>2012-05-11 12:01:14 +0200
commitb4e7f84704b0bb8ed8834d307d24a4c5487619de (patch)
treea291d4cae4317676fae2622cb52c4a8cb7e63964
parentbfdcb1d21fc654eeba9fd75ad5ee0c29b1d7765e (diff)
Fix issue #268
This patch fixes a bug in the message encoder which was responsible for computing incorrect message offset. The bug affected PGM receiver making it unable to decode inital messages.
-rw-r--r--src/encoder.cpp8
-rw-r--r--src/encoder.hpp14
2 files changed, 10 insertions, 12 deletions
diff --git a/src/encoder.cpp b/src/encoder.cpp
index 1075791..f47e38e 100644
--- a/src/encoder.cpp
+++ b/src/encoder.cpp
@@ -51,7 +51,7 @@ bool xs::encoder_t::size_ready ()
{
// Write message body into the buffer.
next_step (in_progress.data (), in_progress.size (),
- &encoder_t::message_ready, false);
+ &encoder_t::message_ready, !(in_progress.flags () & msg_t::more));
return true;
}
@@ -90,15 +90,13 @@ bool xs::encoder_t::message_ready ()
if (size < 255) {
tmpbuf [0] = (unsigned char) size;
tmpbuf [1] = (in_progress.flags () & ~msg_t::shared);
- next_step (tmpbuf, 2, &encoder_t::size_ready,
- !(in_progress.flags () & msg_t::more));
+ next_step (tmpbuf, 2, &encoder_t::size_ready, false);
}
else {
tmpbuf [0] = 0xff;
put_uint64 (tmpbuf + 1, size);
tmpbuf [9] = (in_progress.flags () & ~msg_t::shared);
- next_step (tmpbuf, 10, &encoder_t::size_ready,
- !(in_progress.flags () & msg_t::more));
+ next_step (tmpbuf, 10, &encoder_t::size_ready, false);
}
return true;
}
diff --git a/src/encoder.hpp b/src/encoder.hpp
index 0883f9d..406b28a 100644
--- a/src/encoder.hpp
+++ b/src/encoder.hpp
@@ -83,19 +83,19 @@ namespace xs
// If there are still no data, return what we already have
// in the buffer.
if (!to_write) {
+
+ // If we are to encode the beginning of a new message,
+ // adjust the message offset.
+ if (beginning)
+ if (offset_ && *offset_ == -1)
+ *offset_ = static_cast <int> (pos);
+
if (!(static_cast <T*> (this)->*next) ()) {
*data_ = buffer;
*size_ = pos;
return false;
}
- // If beginning of the message was processed, adjust the
- // first-message-offset.
- if (beginning) {
- if (offset_ && *offset_ == -1)
- *offset_ = (int) pos;
- beginning = false;
- }
}
// If there are no data in the buffer yet and we are able to