Revert "Remove dead code"

This reverts commit fd024e6773.
pull/693/head
Tatsuhiro Tsujikawa 2016-06-12 09:50:51 +09:00
parent 6425ec8684
commit 2dd10c9645
1 changed files with 16 additions and 7 deletions

View File

@ -150,6 +150,14 @@ bool PeerConnection::receiveMessage(unsigned char* data, size_t& dataLength)
else { else {
assert(resbufOffset_ == resbufLength_); assert(resbufOffset_ == resbufLength_);
if (resbufLength_ != 0) { if (resbufLength_ != 0) {
if (msgOffset_ == 0 && resbufLength_ == currentPayloadLength_ + 4) {
// All bytes in buffer have been processed, so clear it
// away.
resbufLength_ = 0;
resbufOffset_ = 0;
msgOffset_ = 0;
}
else {
// Shift buffer so that resbuf_[msgOffset_] moves to // Shift buffer so that resbuf_[msgOffset_] moves to
// rebuf_[0]. // rebuf_[0].
memmove(resbuf_.get(), resbuf_.get() + msgOffset_, memmove(resbuf_.get(), resbuf_.get() + msgOffset_,
@ -158,6 +166,7 @@ bool PeerConnection::receiveMessage(unsigned char* data, size_t& dataLength)
resbufOffset_ = resbufLength_; resbufOffset_ = resbufLength_;
msgOffset_ = 0; msgOffset_ = 0;
} }
}
size_t nread; size_t nread;
// To reduce the amount of copy involved in buffer shift, large // To reduce the amount of copy involved in buffer shift, large
// payload will be read exactly. // payload will be read exactly.