OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <mstcpip.h> | 7 #include <mstcpip.h> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 // isn't able to detect that it's been initialized, so it scans for 0xcd | 686 // isn't able to detect that it's been initialized, so it scans for 0xcd |
687 // in the buffer and reports UMRs (uninitialized memory reads) for those | 687 // in the buffer and reports UMRs (uninitialized memory reads) for those |
688 // individual bytes. We override that in PURIFY builds to avoid the | 688 // individual bytes. We override that in PURIFY builds to avoid the |
689 // false error reports. | 689 // false error reports. |
690 // See bug 5297. | 690 // See bug 5297. |
691 base::MemoryDebug::MarkAsInitialized(core_->read_buffer_.buf, num); | 691 base::MemoryDebug::MarkAsInitialized(core_->read_buffer_.buf, num); |
692 base::StatsCounter read_bytes("tcp.read_bytes"); | 692 base::StatsCounter read_bytes("tcp.read_bytes"); |
693 read_bytes.Add(num); | 693 read_bytes.Add(num); |
694 if (num > 0) | 694 if (num > 0) |
695 use_history_.set_was_used_to_convey_data(); | 695 use_history_.set_was_used_to_convey_data(); |
696 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, num, | 696 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, num, |
697 core_->read_buffer_.buf); | 697 core_->read_buffer_.buf); |
698 return static_cast<int>(num); | 698 return static_cast<int>(num); |
699 } | 699 } |
700 } else { | 700 } else { |
701 int os_error = WSAGetLastError(); | 701 int os_error = WSAGetLastError(); |
702 if (os_error != WSA_IO_PENDING) | 702 if (os_error != WSA_IO_PENDING) |
703 return MapSystemError(os_error); | 703 return MapSystemError(os_error); |
704 } | 704 } |
705 core_->WatchForRead(); | 705 core_->WatchForRead(); |
706 waiting_read_ = true; | 706 waiting_read_ = true; |
707 read_callback_ = callback; | 707 read_callback_ = callback; |
(...skipping 30 matching lines...) Expand all Loading... |
738 // It seems that some winsock interceptors report that more was written | 738 // It seems that some winsock interceptors report that more was written |
739 // than was available. Treat this as an error. http://crbug.com/27870 | 739 // than was available. Treat this as an error. http://crbug.com/27870 |
740 LOG(ERROR) << "Detected broken LSP: Asked to write " << buf_len | 740 LOG(ERROR) << "Detected broken LSP: Asked to write " << buf_len |
741 << " bytes, but " << rv << " bytes reported."; | 741 << " bytes, but " << rv << " bytes reported."; |
742 return ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; | 742 return ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; |
743 } | 743 } |
744 base::StatsCounter write_bytes("tcp.write_bytes"); | 744 base::StatsCounter write_bytes("tcp.write_bytes"); |
745 write_bytes.Add(rv); | 745 write_bytes.Add(rv); |
746 if (rv > 0) | 746 if (rv > 0) |
747 use_history_.set_was_used_to_convey_data(); | 747 use_history_.set_was_used_to_convey_data(); |
748 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, rv, | 748 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, rv, |
749 core_->write_buffer_.buf); | 749 core_->write_buffer_.buf); |
750 return rv; | 750 return rv; |
751 } | 751 } |
752 } else { | 752 } else { |
753 int os_error = WSAGetLastError(); | 753 int os_error = WSAGetLastError(); |
754 if (os_error != WSA_IO_PENDING) | 754 if (os_error != WSA_IO_PENDING) |
755 return MapSystemError(os_error); | 755 return MapSystemError(os_error); |
756 } | 756 } |
757 core_->WatchForWrite(); | 757 core_->WatchForWrite(); |
758 waiting_write_ = true; | 758 waiting_write_ = true; |
759 write_callback_ = callback; | 759 write_callback_ = callback; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 BOOL ok = WSAGetOverlappedResult(socket_, &core_->read_overlapped_, | 856 BOOL ok = WSAGetOverlappedResult(socket_, &core_->read_overlapped_, |
857 &num_bytes, FALSE, &flags); | 857 &num_bytes, FALSE, &flags); |
858 WSAResetEvent(core_->read_overlapped_.hEvent); | 858 WSAResetEvent(core_->read_overlapped_.hEvent); |
859 waiting_read_ = false; | 859 waiting_read_ = false; |
860 core_->read_iobuffer_ = NULL; | 860 core_->read_iobuffer_ = NULL; |
861 if (ok) { | 861 if (ok) { |
862 base::StatsCounter read_bytes("tcp.read_bytes"); | 862 base::StatsCounter read_bytes("tcp.read_bytes"); |
863 read_bytes.Add(num_bytes); | 863 read_bytes.Add(num_bytes); |
864 if (num_bytes > 0) | 864 if (num_bytes > 0) |
865 use_history_.set_was_used_to_convey_data(); | 865 use_history_.set_was_used_to_convey_data(); |
866 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_RECEIVED, num_bytes, | 866 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, |
867 core_->read_buffer_.buf); | 867 num_bytes, core_->read_buffer_.buf); |
868 } | 868 } |
869 DoReadCallback(ok ? num_bytes : MapSystemError(WSAGetLastError())); | 869 DoReadCallback(ok ? num_bytes : MapSystemError(WSAGetLastError())); |
870 } | 870 } |
871 | 871 |
872 void TCPClientSocketWin::DidCompleteWrite() { | 872 void TCPClientSocketWin::DidCompleteWrite() { |
873 DCHECK(waiting_write_); | 873 DCHECK(waiting_write_); |
874 | 874 |
875 DWORD num_bytes, flags; | 875 DWORD num_bytes, flags; |
876 BOOL ok = WSAGetOverlappedResult(socket_, &core_->write_overlapped_, | 876 BOOL ok = WSAGetOverlappedResult(socket_, &core_->write_overlapped_, |
877 &num_bytes, FALSE, &flags); | 877 &num_bytes, FALSE, &flags); |
878 WSAResetEvent(core_->write_overlapped_.hEvent); | 878 WSAResetEvent(core_->write_overlapped_.hEvent); |
879 waiting_write_ = false; | 879 waiting_write_ = false; |
880 int rv; | 880 int rv; |
881 if (!ok) { | 881 if (!ok) { |
882 rv = MapSystemError(WSAGetLastError()); | 882 rv = MapSystemError(WSAGetLastError()); |
883 } else { | 883 } else { |
884 rv = static_cast<int>(num_bytes); | 884 rv = static_cast<int>(num_bytes); |
885 if (rv > core_->write_buffer_length_ || rv < 0) { | 885 if (rv > core_->write_buffer_length_ || rv < 0) { |
886 // It seems that some winsock interceptors report that more was written | 886 // It seems that some winsock interceptors report that more was written |
887 // than was available. Treat this as an error. http://crbug.com/27870 | 887 // than was available. Treat this as an error. http://crbug.com/27870 |
888 LOG(ERROR) << "Detected broken LSP: Asked to write " | 888 LOG(ERROR) << "Detected broken LSP: Asked to write " |
889 << core_->write_buffer_length_ << " bytes, but " << rv | 889 << core_->write_buffer_length_ << " bytes, but " << rv |
890 << " bytes reported."; | 890 << " bytes reported."; |
891 rv = ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; | 891 rv = ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; |
892 } else { | 892 } else { |
893 base::StatsCounter write_bytes("tcp.write_bytes"); | 893 base::StatsCounter write_bytes("tcp.write_bytes"); |
894 write_bytes.Add(num_bytes); | 894 write_bytes.Add(num_bytes); |
895 if (num_bytes > 0) | 895 if (num_bytes > 0) |
896 use_history_.set_was_used_to_convey_data(); | 896 use_history_.set_was_used_to_convey_data(); |
897 LogByteTransfer(net_log_, NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, | 897 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, |
898 core_->write_buffer_.buf); | 898 core_->write_buffer_.buf); |
899 } | 899 } |
900 } | 900 } |
901 core_->write_iobuffer_ = NULL; | 901 core_->write_iobuffer_ = NULL; |
902 DoWriteCallback(rv); | 902 DoWriteCallback(rv); |
903 } | 903 } |
904 | 904 |
905 } // namespace net | 905 } // namespace net |
OLD | NEW |