| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 #endif // USE_SSLSTREAM | 74 #endif // USE_SSLSTREAM |
| 75 } | 75 } |
| 76 | 76 |
| 77 #ifndef USE_SSLSTREAM | 77 #ifndef USE_SSLSTREAM |
| 78 void XmppSocket::OnReadEvent(rtc::AsyncSocket * socket) { | 78 void XmppSocket::OnReadEvent(rtc::AsyncSocket * socket) { |
| 79 SignalRead(); | 79 SignalRead(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void XmppSocket::OnWriteEvent(rtc::AsyncSocket * socket) { | 82 void XmppSocket::OnWriteEvent(rtc::AsyncSocket * socket) { |
| 83 // Write bytes if there are any | 83 // Write bytes if there are any |
| 84 while (buffer_.Length() != 0) { | 84 while (buffer_.size() > 0) { |
| 85 int written = cricket_socket_->Send(buffer_.Data(), buffer_.Length()); | 85 int written = cricket_socket_->Send(buffer_.data(), buffer_.size()); |
| 86 if (written > 0) { | 86 if (written > 0) { |
| 87 buffer_.Consume(written); | 87 ASSERT(static_cast<size_t>(written) <= buffer_.size()); |
| 88 memmove(buffer_.data(), buffer_.data() + written, |
| 89 buffer_.size() - written); |
| 90 buffer_.SetSize(buffer_.size() - written); |
| 88 continue; | 91 continue; |
| 89 } | 92 } |
| 90 if (!cricket_socket_->IsBlocking()) | 93 if (!cricket_socket_->IsBlocking()) |
| 91 LOG(LS_ERROR) << "Send error: " << cricket_socket_->GetError(); | 94 LOG(LS_ERROR) << "Send error: " << cricket_socket_->GetError(); |
| 92 return; | 95 return; |
| 93 } | 96 } |
| 94 } | 97 } |
| 95 | 98 |
| 96 void XmppSocket::OnConnectEvent(rtc::AsyncSocket * socket) { | 99 void XmppSocket::OnConnectEvent(rtc::AsyncSocket * socket) { |
| 97 #if defined(FEATURE_ENABLE_SSL) | 100 #if defined(FEATURE_ENABLE_SSL) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 124 #endif | 127 #endif |
| 125 { | 128 { |
| 126 state_ = buzz::AsyncSocket::STATE_OPEN; | 129 state_ = buzz::AsyncSocket::STATE_OPEN; |
| 127 SignalConnected(); | 130 SignalConnected(); |
| 128 } | 131 } |
| 129 } | 132 } |
| 130 if ((events & rtc::SE_READ)) | 133 if ((events & rtc::SE_READ)) |
| 131 SignalRead(); | 134 SignalRead(); |
| 132 if ((events & rtc::SE_WRITE)) { | 135 if ((events & rtc::SE_WRITE)) { |
| 133 // Write bytes if there are any | 136 // Write bytes if there are any |
| 134 while (buffer_.Length() != 0) { | 137 while (buffer_.size() > 0) { |
| 135 rtc::StreamResult result; | 138 rtc::StreamResult result; |
| 136 size_t written; | 139 size_t written; |
| 137 int error; | 140 int error; |
| 138 result = stream_->Write(buffer_.Data(), buffer_.Length(), | 141 result = stream_->Write(buffer_.data(), buffer_.size(), |
| 139 &written, &error); | 142 &written, &error); |
| 140 if (result == rtc::SR_ERROR) { | 143 if (result == rtc::SR_ERROR) { |
| 141 LOG(LS_ERROR) << "Send error: " << error; | 144 LOG(LS_ERROR) << "Send error: " << error; |
| 142 return; | 145 return; |
| 143 } | 146 } |
| 144 if (result == rtc::SR_BLOCK) | 147 if (result == rtc::SR_BLOCK) |
| 145 return; | 148 return; |
| 146 ASSERT(result == rtc::SR_SUCCESS); | 149 ASSERT(result == rtc::SR_SUCCESS); |
| 147 ASSERT(written > 0); | 150 ASSERT(written > 0); |
| 148 buffer_.Shift(written); | 151 ASSERT(written <= buffer_.size()); |
| 152 memmove(buffer_.data(), buffer_.data() + written, |
| 153 buffer_.size() - written); |
| 154 buffer_.SetSize(buffer_.size() - written); |
| 149 } | 155 } |
| 150 } | 156 } |
| 151 if ((events & rtc::SE_CLOSE)) | 157 if ((events & rtc::SE_CLOSE)) |
| 152 SignalCloseEvent(err); | 158 SignalCloseEvent(err); |
| 153 } | 159 } |
| 154 #endif // USE_SSLSTREAM | 160 #endif // USE_SSLSTREAM |
| 155 | 161 |
| 156 buzz::AsyncSocket::State XmppSocket::state() { | 162 buzz::AsyncSocket::State XmppSocket::state() { |
| 157 return state_; | 163 return state_; |
| 158 } | 164 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 184 } | 190 } |
| 185 #else // USE_SSLSTREAM | 191 #else // USE_SSLSTREAM |
| 186 rtc::StreamResult result = stream_->Read(data, len, len_read, NULL); | 192 rtc::StreamResult result = stream_->Read(data, len, len_read, NULL); |
| 187 if (result == rtc::SR_SUCCESS) | 193 if (result == rtc::SR_SUCCESS) |
| 188 return true; | 194 return true; |
| 189 #endif // USE_SSLSTREAM | 195 #endif // USE_SSLSTREAM |
| 190 return false; | 196 return false; |
| 191 } | 197 } |
| 192 | 198 |
| 193 bool XmppSocket::Write(const char * data, size_t len) { | 199 bool XmppSocket::Write(const char * data, size_t len) { |
| 194 buffer_.WriteBytes(data, len); | 200 buffer_.AppendData(data, len); |
| 195 #ifndef USE_SSLSTREAM | 201 #ifndef USE_SSLSTREAM |
| 196 OnWriteEvent(cricket_socket_); | 202 OnWriteEvent(cricket_socket_); |
| 197 #else // USE_SSLSTREAM | 203 #else // USE_SSLSTREAM |
| 198 OnEvent(stream_, rtc::SE_WRITE, 0); | 204 OnEvent(stream_, rtc::SE_WRITE, 0); |
| 199 #endif // USE_SSLSTREAM | 205 #endif // USE_SSLSTREAM |
| 200 return true; | 206 return true; |
| 201 } | 207 } |
| 202 | 208 |
| 203 bool XmppSocket::Close() { | 209 bool XmppSocket::Close() { |
| 204 if (state_ != buzz::AsyncSocket::STATE_OPEN) | 210 if (state_ != buzz::AsyncSocket::STATE_OPEN) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 235 #endif // USE_SSLSTREAM | 241 #endif // USE_SSLSTREAM |
| 236 state_ = buzz::AsyncSocket::STATE_TLS_CONNECTING; | 242 state_ = buzz::AsyncSocket::STATE_TLS_CONNECTING; |
| 237 return true; | 243 return true; |
| 238 #else // !defined(FEATURE_ENABLE_SSL) | 244 #else // !defined(FEATURE_ENABLE_SSL) |
| 239 return false; | 245 return false; |
| 240 #endif // !defined(FEATURE_ENABLE_SSL) | 246 #endif // !defined(FEATURE_ENABLE_SSL) |
| 241 } | 247 } |
| 242 | 248 |
| 243 } // namespace buzz | 249 } // namespace buzz |
| 244 | 250 |
| OLD | NEW |