| 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 "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 if (socket_write_pending_) | 353 if (socket_write_pending_) |
| 354 return IPseudoTcpNotify::WR_SUCCESS; | 354 return IPseudoTcpNotify::WR_SUCCESS; |
| 355 | 355 |
| 356 scoped_refptr<net::IOBuffer> write_buffer = new net::IOBuffer(len); | 356 scoped_refptr<net::IOBuffer> write_buffer = new net::IOBuffer(len); |
| 357 memcpy(write_buffer->data(), buffer, len); | 357 memcpy(write_buffer->data(), buffer, len); |
| 358 | 358 |
| 359 // Our underlying socket is datagram-oriented, which means it should either | 359 // Our underlying socket is datagram-oriented, which means it should either |
| 360 // send exactly as many bytes as we requested, or fail. | 360 // send exactly as many bytes as we requested, or fail. |
| 361 int result; | 361 int result; |
| 362 if (socket_.get()) { | 362 if (socket_.get()) { |
| 363 result = socket_->Write(write_buffer, len, | 363 result = socket_->Write( |
| 364 base::Bind(&PseudoTcpAdapter::Core::OnWritten, | 364 write_buffer.get(), |
| 365 base::Unretained(this))); | 365 len, |
| 366 base::Bind(&PseudoTcpAdapter::Core::OnWritten, base::Unretained(this))); |
| 366 } else { | 367 } else { |
| 367 result = net::ERR_CONNECTION_CLOSED; | 368 result = net::ERR_CONNECTION_CLOSED; |
| 368 } | 369 } |
| 369 if (result == net::ERR_IO_PENDING) { | 370 if (result == net::ERR_IO_PENDING) { |
| 370 socket_write_pending_ = true; | 371 socket_write_pending_ = true; |
| 371 return IPseudoTcpNotify::WR_SUCCESS; | 372 return IPseudoTcpNotify::WR_SUCCESS; |
| 372 } if (result == net::ERR_MSG_TOO_BIG) { | 373 } if (result == net::ERR_MSG_TOO_BIG) { |
| 373 return IPseudoTcpNotify::WR_TOO_LARGE; | 374 return IPseudoTcpNotify::WR_TOO_LARGE; |
| 374 } else if (result < 0) { | 375 } else if (result < 0) { |
| 375 return IPseudoTcpNotify::WR_FAIL; | 376 return IPseudoTcpNotify::WR_FAIL; |
| 376 } else { | 377 } else { |
| 377 return IPseudoTcpNotify::WR_SUCCESS; | 378 return IPseudoTcpNotify::WR_SUCCESS; |
| 378 } | 379 } |
| 379 } | 380 } |
| 380 | 381 |
| 381 void PseudoTcpAdapter::Core::DoReadFromSocket() { | 382 void PseudoTcpAdapter::Core::DoReadFromSocket() { |
| 382 if (!socket_read_buffer_) | 383 if (!socket_read_buffer_.get()) |
| 383 socket_read_buffer_ = new net::IOBuffer(kReadBufferSize); | 384 socket_read_buffer_ = new net::IOBuffer(kReadBufferSize); |
| 384 | 385 |
| 385 int result = 1; | 386 int result = 1; |
| 386 while (socket_.get() && result > 0) { | 387 while (socket_.get() && result > 0) { |
| 387 result = socket_->Read(socket_read_buffer_, kReadBufferSize, | 388 result = socket_->Read( |
| 388 base::Bind(&PseudoTcpAdapter::Core::OnRead, | 389 socket_read_buffer_.get(), |
| 389 base::Unretained(this))); | 390 kReadBufferSize, |
| 391 base::Bind(&PseudoTcpAdapter::Core::OnRead, base::Unretained(this))); |
| 390 if (result != net::ERR_IO_PENDING) | 392 if (result != net::ERR_IO_PENDING) |
| 391 HandleReadResults(result); | 393 HandleReadResults(result); |
| 392 } | 394 } |
| 393 } | 395 } |
| 394 | 396 |
| 395 void PseudoTcpAdapter::Core::HandleReadResults(int result) { | 397 void PseudoTcpAdapter::Core::HandleReadResults(int result) { |
| 396 if (result <= 0) { | 398 if (result <= 0) { |
| 397 LOG(ERROR) << "Read returned " << result; | 399 LOG(ERROR) << "Read returned " << result; |
| 398 return; | 400 return; |
| 399 } | 401 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 DCHECK(CalledOnValidThread()); | 589 DCHECK(CalledOnValidThread()); |
| 588 core_->SetNoDelay(no_delay); | 590 core_->SetNoDelay(no_delay); |
| 589 } | 591 } |
| 590 | 592 |
| 591 void PseudoTcpAdapter::SetWriteWaitsForSend(bool write_waits_for_send) { | 593 void PseudoTcpAdapter::SetWriteWaitsForSend(bool write_waits_for_send) { |
| 592 DCHECK(CalledOnValidThread()); | 594 DCHECK(CalledOnValidThread()); |
| 593 core_->SetWriteWaitsForSend(write_waits_for_send); | 595 core_->SetWriteWaitsForSend(write_waits_for_send); |
| 594 } | 596 } |
| 595 | 597 |
| 596 } // namespace jingle_glue | 598 } // namespace jingle_glue |
| OLD | NEW |