OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "jingle/glue/pseudotcp_adapter.h" | 5 #include "jingle/glue/pseudotcp_adapter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 225 |
226 void DoWrite() { | 226 void DoWrite() { |
227 int result = 1; | 227 int result = 1; |
228 while (result > 0) { | 228 while (result > 0) { |
229 if (output_buffer_->BytesRemaining() == 0) | 229 if (output_buffer_->BytesRemaining() == 0) |
230 break; | 230 break; |
231 | 231 |
232 int bytes_to_write = std::min(output_buffer_->BytesRemaining(), | 232 int bytes_to_write = std::min(output_buffer_->BytesRemaining(), |
233 kMessageSize); | 233 kMessageSize); |
234 result = client_socket_->Write( | 234 result = client_socket_->Write( |
235 output_buffer_, bytes_to_write, | 235 output_buffer_.get(), bytes_to_write, |
236 base::Bind(&TCPChannelTester::OnWritten, base::Unretained(this))); | 236 base::Bind(&TCPChannelTester::OnWritten, base::Unretained(this))); |
237 HandleWriteResult(result); | 237 HandleWriteResult(result); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 void OnWritten(int result) { | 241 void OnWritten(int result) { |
242 HandleWriteResult(result); | 242 HandleWriteResult(result); |
243 DoWrite(); | 243 DoWrite(); |
244 } | 244 } |
245 | 245 |
246 void HandleWriteResult(int result) { | 246 void HandleWriteResult(int result) { |
247 if (result <= 0 && result != net::ERR_IO_PENDING) { | 247 if (result <= 0 && result != net::ERR_IO_PENDING) { |
248 LOG(ERROR) << "Received error " << result << " when trying to write"; | 248 LOG(ERROR) << "Received error " << result << " when trying to write"; |
249 write_errors_++; | 249 write_errors_++; |
250 Done(); | 250 Done(); |
251 } else if (result > 0) { | 251 } else if (result > 0) { |
252 output_buffer_->DidConsume(result); | 252 output_buffer_->DidConsume(result); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 void DoRead() { | 256 void DoRead() { |
257 int result = 1; | 257 int result = 1; |
258 while (result > 0) { | 258 while (result > 0) { |
259 input_buffer_->set_offset(input_buffer_->capacity() - kMessageSize); | 259 input_buffer_->set_offset(input_buffer_->capacity() - kMessageSize); |
260 | 260 |
261 result = host_socket_->Read(input_buffer_, kMessageSize, | 261 result = host_socket_->Read(input_buffer_.get(), kMessageSize, |
262 base::Bind(&TCPChannelTester::OnRead, | 262 base::Bind(&TCPChannelTester::OnRead, |
263 base::Unretained(this))); | 263 base::Unretained(this))); |
264 HandleReadResult(result); | 264 HandleReadResult(result); |
265 }; | 265 }; |
266 } | 266 } |
267 | 267 |
268 void OnRead(int result) { | 268 void OnRead(int result) { |
269 HandleReadResult(result); | 269 HandleReadResult(result); |
270 DoRead(); | 270 DoRead(); |
271 } | 271 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 client_pseudotcp_.get()); | 437 client_pseudotcp_.get()); |
438 | 438 |
439 tester->Start(); | 439 tester->Start(); |
440 message_loop_.Run(); | 440 message_loop_.Run(); |
441 tester->CheckResults(); | 441 tester->CheckResults(); |
442 } | 442 } |
443 | 443 |
444 } // namespace | 444 } // namespace |
445 | 445 |
446 } // namespace jingle_glue | 446 } // namespace jingle_glue |
OLD | NEW |