OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/socket/tcp_client_socket_win.h" | 5 #include "net/socket/tcp_client_socket_win.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory_debug.h" | 9 #include "base/memory_debug.h" |
10 #include "base/stats_counters.h" | 10 #include "base/stats_counters.h" |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 | 470 |
471 // Because of how WSARecv fills memory when used asynchronously, Purify | 471 // Because of how WSARecv fills memory when used asynchronously, Purify |
472 // isn't able to detect that it's been initialized, so it scans for 0xcd | 472 // isn't able to detect that it's been initialized, so it scans for 0xcd |
473 // in the buffer and reports UMRs (uninitialized memory reads) for those | 473 // in the buffer and reports UMRs (uninitialized memory reads) for those |
474 // individual bytes. We override that in PURIFY builds to avoid the | 474 // individual bytes. We override that in PURIFY builds to avoid the |
475 // false error reports. | 475 // false error reports. |
476 // See bug 5297. | 476 // See bug 5297. |
477 base::MemoryDebug::MarkAsInitialized(core_->read_buffer_.buf, num); | 477 base::MemoryDebug::MarkAsInitialized(core_->read_buffer_.buf, num); |
478 static StatsCounter read_bytes("tcp.read_bytes"); | 478 static StatsCounter read_bytes("tcp.read_bytes"); |
479 read_bytes.Add(num); | 479 read_bytes.Add(num); |
480 net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_RECEIVED, num); | 480 net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_RECEIVED, |
| 481 "num_bytes", num); |
481 return static_cast<int>(num); | 482 return static_cast<int>(num); |
482 } | 483 } |
483 } else { | 484 } else { |
484 int os_error = WSAGetLastError(); | 485 int os_error = WSAGetLastError(); |
485 if (os_error != WSA_IO_PENDING) | 486 if (os_error != WSA_IO_PENDING) |
486 return MapWinsockError(os_error); | 487 return MapWinsockError(os_error); |
487 } | 488 } |
488 core_->WatchForRead(); | 489 core_->WatchForRead(); |
489 waiting_read_ = true; | 490 waiting_read_ = true; |
490 read_callback_ = callback; | 491 read_callback_ = callback; |
(...skipping 30 matching lines...) Expand all Loading... |
521 if (rv > buf_len || rv < 0) { | 522 if (rv > buf_len || rv < 0) { |
522 // It seems that some winsock interceptors report that more was written | 523 // It seems that some winsock interceptors report that more was written |
523 // than was available. Treat this as an error. http://crbug.com/27870 | 524 // than was available. Treat this as an error. http://crbug.com/27870 |
524 LOG(ERROR) << "Detected broken LSP: Asked to write " << buf_len | 525 LOG(ERROR) << "Detected broken LSP: Asked to write " << buf_len |
525 << " bytes, but " << rv << " bytes reported."; | 526 << " bytes, but " << rv << " bytes reported."; |
526 return ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; | 527 return ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; |
527 } | 528 } |
528 TRACE_EVENT_END("socket.write", this, StringPrintf("%d bytes", rv)); | 529 TRACE_EVENT_END("socket.write", this, StringPrintf("%d bytes", rv)); |
529 static StatsCounter write_bytes("tcp.write_bytes"); | 530 static StatsCounter write_bytes("tcp.write_bytes"); |
530 write_bytes.Add(rv); | 531 write_bytes.Add(rv); |
531 net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_SENT, rv); | 532 net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_SENT, |
| 533 "num_bytes", rv); |
532 return rv; | 534 return rv; |
533 } | 535 } |
534 } else { | 536 } else { |
535 int os_error = WSAGetLastError(); | 537 int os_error = WSAGetLastError(); |
536 if (os_error != WSA_IO_PENDING) | 538 if (os_error != WSA_IO_PENDING) |
537 return MapWinsockError(os_error); | 539 return MapWinsockError(os_error); |
538 } | 540 } |
539 core_->WatchForWrite(); | 541 core_->WatchForWrite(); |
540 waiting_write_ = true; | 542 waiting_write_ = true; |
541 write_callback_ = callback; | 543 write_callback_ = callback; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 | 686 |
685 void TCPClientSocketWin::DidCompleteRead() { | 687 void TCPClientSocketWin::DidCompleteRead() { |
686 DCHECK(waiting_read_); | 688 DCHECK(waiting_read_); |
687 DWORD num_bytes, flags; | 689 DWORD num_bytes, flags; |
688 BOOL ok = WSAGetOverlappedResult(socket_, &core_->read_overlapped_, | 690 BOOL ok = WSAGetOverlappedResult(socket_, &core_->read_overlapped_, |
689 &num_bytes, FALSE, &flags); | 691 &num_bytes, FALSE, &flags); |
690 WSAResetEvent(core_->read_overlapped_.hEvent); | 692 WSAResetEvent(core_->read_overlapped_.hEvent); |
691 TRACE_EVENT_END("socket.read", this, StringPrintf("%d bytes", num_bytes)); | 693 TRACE_EVENT_END("socket.read", this, StringPrintf("%d bytes", num_bytes)); |
692 waiting_read_ = false; | 694 waiting_read_ = false; |
693 core_->read_iobuffer_ = NULL; | 695 core_->read_iobuffer_ = NULL; |
694 if (ok) | 696 if (ok) { |
695 net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_RECEIVED, num_bytes); | 697 net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_RECEIVED, |
| 698 "num_bytes", num_bytes); |
| 699 } |
696 DoReadCallback(ok ? num_bytes : MapWinsockError(WSAGetLastError())); | 700 DoReadCallback(ok ? num_bytes : MapWinsockError(WSAGetLastError())); |
697 } | 701 } |
698 | 702 |
699 void TCPClientSocketWin::DidCompleteWrite() { | 703 void TCPClientSocketWin::DidCompleteWrite() { |
700 DCHECK(waiting_write_); | 704 DCHECK(waiting_write_); |
701 | 705 |
702 DWORD num_bytes, flags; | 706 DWORD num_bytes, flags; |
703 BOOL ok = WSAGetOverlappedResult(socket_, &core_->write_overlapped_, | 707 BOOL ok = WSAGetOverlappedResult(socket_, &core_->write_overlapped_, |
704 &num_bytes, FALSE, &flags); | 708 &num_bytes, FALSE, &flags); |
705 WSAResetEvent(core_->write_overlapped_.hEvent); | 709 WSAResetEvent(core_->write_overlapped_.hEvent); |
706 TRACE_EVENT_END("socket.write", this, StringPrintf("%d bytes", num_bytes)); | 710 TRACE_EVENT_END("socket.write", this, StringPrintf("%d bytes", num_bytes)); |
707 waiting_write_ = false; | 711 waiting_write_ = false; |
708 int rv; | 712 int rv; |
709 if (!ok) { | 713 if (!ok) { |
710 rv = MapWinsockError(WSAGetLastError()); | 714 rv = MapWinsockError(WSAGetLastError()); |
711 } else { | 715 } else { |
712 rv = static_cast<int>(num_bytes); | 716 rv = static_cast<int>(num_bytes); |
713 if (rv > core_->write_buffer_length_ || rv < 0) { | 717 if (rv > core_->write_buffer_length_ || rv < 0) { |
714 // It seems that some winsock interceptors report that more was written | 718 // It seems that some winsock interceptors report that more was written |
715 // than was available. Treat this as an error. http://crbug.com/27870 | 719 // than was available. Treat this as an error. http://crbug.com/27870 |
716 LOG(ERROR) << "Detected broken LSP: Asked to write " | 720 LOG(ERROR) << "Detected broken LSP: Asked to write " |
717 << core_->write_buffer_length_ << " bytes, but " << rv | 721 << core_->write_buffer_length_ << " bytes, but " << rv |
718 << " bytes reported."; | 722 << " bytes reported."; |
719 rv = ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; | 723 rv = ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; |
720 } else { | 724 } else { |
721 net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_SENT, rv); | 725 net_log_.AddEventWithInteger(NetLog::TYPE_SOCKET_BYTES_SENT, |
| 726 "num_bytes", rv); |
722 } | 727 } |
723 } | 728 } |
724 core_->write_iobuffer_ = NULL; | 729 core_->write_iobuffer_ = NULL; |
725 DoWriteCallback(rv); | 730 DoWriteCallback(rv); |
726 } | 731 } |
727 | 732 |
728 } // namespace net | 733 } // namespace net |
OLD | NEW |