diff options
author | mukesh agrawal <quiche@google.com> | 2016-10-05 14:03:17 -0700 |
---|---|---|
committer | mukesh agrawal <quiche@google.com> | 2016-10-05 17:52:53 -0700 |
commit | b0ef31514a28871bf7d2435e4b5aada60e813ce1 (patch) | |
tree | 269bab7f5623e4d77d142b9ed287f24ff798c12a /message_buffer.h | |
parent | 6306897b7f84708d86774bcbfe2b7b0e629cd49e (diff) | |
download | wifilogd-b0ef31514a28871bf7d2435e4b5aada60e813ce1.tar.gz |
MessageBuffer: use CopyFromBufferOrDie()
Update ConsumeNextMessage() to make use of
local_utils::CopyFromBufferOrDie(). This (hopefully)
accomplishes two things:
- makes the code a bit more obvious, and
- makes the code more consistent with CommandProcessor
Along the way: fix a bug in the way that we check
that the MessageBuffer contains enough bytes for
a LengthHeader.
(Previously, we were checking that the LengthHeader
fit within the memory bounds of |data_|. Really,
though, we should check that the LengthHeader fits
within the populated area of |data_|.)
Bug: 31971382
Test: ./runtests.sh (on bullhead)
Change-Id: Ie3a4c38fefb69a3212142a53e79fdc720af6c601
Diffstat (limited to 'message_buffer.h')
-rw-r--r-- | message_buffer.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/message_buffer.h b/message_buffer.h index 1a1932b..15e394e 100644 --- a/message_buffer.h +++ b/message_buffer.h @@ -82,6 +82,10 @@ class MessageBuffer { // Writes arbitrary data into the buffer. void AppendRawBytes(NONNULL const void* data_start, size_t data_len); + // Returns the total number of bytes available for reading. This number + // includes headers. + size_t GetReadableSize() const { return write_pos_ - read_pos_; } + std::unique_ptr<uint8_t[]> data_; size_t capacity_; size_t read_pos_; |