Index: webrtc/libjingle/xmpp/xmppsocket.cc |
diff --git a/webrtc/libjingle/xmpp/xmppsocket.cc b/webrtc/libjingle/xmpp/xmppsocket.cc |
index 25e03efbe9271acb0e1dc3f94939fd2a3982f6f9..981815872b35a3e3744ed28e8836c12e154e625d 100644 |
--- a/webrtc/libjingle/xmpp/xmppsocket.cc |
+++ b/webrtc/libjingle/xmpp/xmppsocket.cc |
@@ -81,10 +81,13 @@ void XmppSocket::OnReadEvent(rtc::AsyncSocket * socket) { |
void XmppSocket::OnWriteEvent(rtc::AsyncSocket * socket) { |
// Write bytes if there are any |
- while (buffer_.Length() != 0) { |
- int written = cricket_socket_->Send(buffer_.Data(), buffer_.Length()); |
+ while (buffer_.size() > 0) { |
+ int written = cricket_socket_->Send(buffer_.data(), buffer_.size()); |
if (written > 0) { |
- buffer_.Consume(written); |
+ ASSERT(static_cast<size_t>(written) <= buffer_.size()); |
+ memmove(buffer_.data(), buffer_.data() + written, |
+ buffer_.size() - written); |
+ buffer_.SetSize(buffer_.size() - written); |
continue; |
} |
if (!cricket_socket_->IsBlocking()) |
@@ -131,11 +134,11 @@ void XmppSocket::OnEvent(rtc::StreamInterface* stream, |
SignalRead(); |
if ((events & rtc::SE_WRITE)) { |
// Write bytes if there are any |
- while (buffer_.Length() != 0) { |
+ while (buffer_.size() > 0) { |
rtc::StreamResult result; |
size_t written; |
int error; |
- result = stream_->Write(buffer_.Data(), buffer_.Length(), |
+ result = stream_->Write(buffer_.data(), buffer_.size(), |
&written, &error); |
if (result == rtc::SR_ERROR) { |
LOG(LS_ERROR) << "Send error: " << error; |
@@ -145,7 +148,10 @@ void XmppSocket::OnEvent(rtc::StreamInterface* stream, |
return; |
ASSERT(result == rtc::SR_SUCCESS); |
ASSERT(written > 0); |
- buffer_.Shift(written); |
+ ASSERT(written <= buffer_.size()); |
+ memmove(buffer_.data(), buffer_.data() + written, |
+ buffer_.size() - written); |
+ buffer_.SetSize(buffer_.size() - written); |
} |
} |
if ((events & rtc::SE_CLOSE)) |
@@ -191,7 +197,7 @@ bool XmppSocket::Read(char * data, size_t len, size_t* len_read) { |
} |
bool XmppSocket::Write(const char * data, size_t len) { |
- buffer_.WriteBytes(data, len); |
+ buffer_.AppendData(data, len); |
#ifndef USE_SSLSTREAM |
OnWriteEvent(cricket_socket_); |
#else // USE_SSLSTREAM |