| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 void DoWrite() { | 225 void DoWrite() { |
| 226 int result = 1; | 226 int result = 1; |
| 227 while (result > 0) { | 227 while (result > 0) { |
| 228 if (output_buffer_->BytesRemaining() == 0) | 228 if (output_buffer_->BytesRemaining() == 0) |
| 229 break; | 229 break; |
| 230 | 230 |
| 231 int bytes_to_write = std::min(output_buffer_->BytesRemaining(), | 231 int bytes_to_write = std::min(output_buffer_->BytesRemaining(), |
| 232 kMessageSize); | 232 kMessageSize); |
| 233 result = client_socket_->Write( | 233 result = client_socket_->Write( |
| 234 output_buffer_, bytes_to_write, | 234 output_buffer_.get(), |
| 235 bytes_to_write, |
| 235 base::Bind(&TCPChannelTester::OnWritten, base::Unretained(this))); | 236 base::Bind(&TCPChannelTester::OnWritten, base::Unretained(this))); |
| 236 HandleWriteResult(result); | 237 HandleWriteResult(result); |
| 237 } | 238 } |
| 238 } | 239 } |
| 239 | 240 |
| 240 void OnWritten(int result) { | 241 void OnWritten(int result) { |
| 241 HandleWriteResult(result); | 242 HandleWriteResult(result); |
| 242 DoWrite(); | 243 DoWrite(); |
| 243 } | 244 } |
| 244 | 245 |
| 245 void HandleWriteResult(int result) { | 246 void HandleWriteResult(int result) { |
| 246 if (result <= 0 && result != net::ERR_IO_PENDING) { | 247 if (result <= 0 && result != net::ERR_IO_PENDING) { |
| 247 LOG(ERROR) << "Received error " << result << " when trying to write"; | 248 LOG(ERROR) << "Received error " << result << " when trying to write"; |
| 248 write_errors_++; | 249 write_errors_++; |
| 249 Done(); | 250 Done(); |
| 250 } else if (result > 0) { | 251 } else if (result > 0) { |
| 251 output_buffer_->DidConsume(result); | 252 output_buffer_->DidConsume(result); |
| 252 } | 253 } |
| 253 } | 254 } |
| 254 | 255 |
| 255 void DoRead() { | 256 void DoRead() { |
| 256 int result = 1; | 257 int result = 1; |
| 257 while (result > 0) { | 258 while (result > 0) { |
| 258 input_buffer_->set_offset(input_buffer_->capacity() - kMessageSize); | 259 input_buffer_->set_offset(input_buffer_->capacity() - kMessageSize); |
| 259 | 260 |
| 260 result = host_socket_->Read(input_buffer_, kMessageSize, | 261 result = host_socket_->Read( |
| 261 base::Bind(&TCPChannelTester::OnRead, | 262 input_buffer_.get(), |
| 262 base::Unretained(this))); | 263 kMessageSize, |
| 264 base::Bind(&TCPChannelTester::OnRead, base::Unretained(this))); |
| 263 HandleReadResult(result); | 265 HandleReadResult(result); |
| 264 }; | 266 }; |
| 265 } | 267 } |
| 266 | 268 |
| 267 void OnRead(int result) { | 269 void OnRead(int result) { |
| 268 HandleReadResult(result); | 270 HandleReadResult(result); |
| 269 DoRead(); | 271 DoRead(); |
| 270 } | 272 } |
| 271 | 273 |
| 272 void HandleReadResult(int result) { | 274 void HandleReadResult(int result) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 client_pseudotcp_.get()); | 438 client_pseudotcp_.get()); |
| 437 | 439 |
| 438 tester->Start(); | 440 tester->Start(); |
| 439 message_loop_.Run(); | 441 message_loop_.Run(); |
| 440 tester->CheckResults(); | 442 tester->CheckResults(); |
| 441 } | 443 } |
| 442 | 444 |
| 443 } // namespace | 445 } // namespace |
| 444 | 446 |
| 445 } // namespace jingle_glue | 447 } // namespace jingle_glue |
| OLD | NEW |