Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: net/socket/tcp_client_socket_win.cc

Issue 12468002: Report the correct os_error in the SOCKET_READ_ERROR event (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "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 939 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 LogConnectCompletion(rv); 950 LogConnectCompletion(rv);
951 DoReadCallback(rv); 951 DoReadCallback(rv);
952 } 952 }
953 } 953 }
954 954
955 void TCPClientSocketWin::DidCompleteRead() { 955 void TCPClientSocketWin::DidCompleteRead() {
956 DCHECK(waiting_read_); 956 DCHECK(waiting_read_);
957 DWORD num_bytes, flags; 957 DWORD num_bytes, flags;
958 BOOL ok = WSAGetOverlappedResult(socket_, &core_->read_overlapped_, 958 BOOL ok = WSAGetOverlappedResult(socket_, &core_->read_overlapped_,
959 &num_bytes, FALSE, &flags); 959 &num_bytes, FALSE, &flags);
960 WSAResetEvent(core_->read_overlapped_.hEvent);
961 waiting_read_ = false; 960 waiting_read_ = false;
962 int rv; 961 int rv;
963 if (ok) { 962 if (ok) {
964 base::StatsCounter read_bytes("tcp.read_bytes"); 963 base::StatsCounter read_bytes("tcp.read_bytes");
965 read_bytes.Add(num_bytes); 964 read_bytes.Add(num_bytes);
966 num_bytes_read_ += num_bytes; 965 num_bytes_read_ += num_bytes;
967 if (num_bytes > 0) 966 if (num_bytes > 0)
968 use_history_.set_was_used_to_convey_data(); 967 use_history_.set_was_used_to_convey_data();
969 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, 968 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED,
970 num_bytes, core_->read_iobuffer_->data()); 969 num_bytes, core_->read_iobuffer_->data());
971 rv = static_cast<int>(num_bytes); 970 rv = static_cast<int>(num_bytes);
972 } else { 971 } else {
973 int os_error = WSAGetLastError(); 972 int os_error = WSAGetLastError();
974 rv = MapSystemError(os_error); 973 rv = MapSystemError(os_error);
975 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, 974 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR,
976 CreateNetLogSocketErrorCallback(rv, os_error)); 975 CreateNetLogSocketErrorCallback(rv, os_error));
977 } 976 }
977 WSAResetEvent(core_->read_overlapped_.hEvent);
wtc 2013/03/05 20:17:03 This change is just defensive programming. Between
978 core_->read_iobuffer_ = NULL; 978 core_->read_iobuffer_ = NULL;
979 core_->read_buffer_length_ = 0; 979 core_->read_buffer_length_ = 0;
980 DoReadCallback(rv); 980 DoReadCallback(rv);
981 } 981 }
982 982
983 void TCPClientSocketWin::DidCompleteWrite() { 983 void TCPClientSocketWin::DidCompleteWrite() {
984 DCHECK(waiting_write_); 984 DCHECK(waiting_write_);
985 985
986 DWORD num_bytes, flags; 986 DWORD num_bytes, flags;
987 BOOL ok = WSAGetOverlappedResult(socket_, &core_->write_overlapped_, 987 BOOL ok = WSAGetOverlappedResult(socket_, &core_->write_overlapped_,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 void TCPClientSocketWin::DidSignalRead() { 1019 void TCPClientSocketWin::DidSignalRead() {
1020 DCHECK(waiting_read_); 1020 DCHECK(waiting_read_);
1021 int os_error = 0; 1021 int os_error = 0;
1022 WSANETWORKEVENTS network_events; 1022 WSANETWORKEVENTS network_events;
1023 int rv = WSAEnumNetworkEvents(socket_, core_->read_overlapped_.hEvent, 1023 int rv = WSAEnumNetworkEvents(socket_, core_->read_overlapped_.hEvent,
1024 &network_events); 1024 &network_events);
1025 if (rv == SOCKET_ERROR) { 1025 if (rv == SOCKET_ERROR) {
1026 os_error = WSAGetLastError(); 1026 os_error = WSAGetLastError();
1027 rv = MapSystemError(os_error); 1027 rv = MapSystemError(os_error);
1028 } else if (network_events.lNetworkEvents & FD_READ) { 1028 } else if (network_events.lNetworkEvents & FD_READ) {
1029 rv = DoRead(core_->read_iobuffer_, core_->read_buffer_length_, 1029 if (network_events.iErrorCode[FD_READ_BIT]) {
wtc 2013/03/05 20:17:03 According to MSDN documentation and the sample cod
rvargas (doing something else) 2013/03/05 23:14:07 could you point me to that sample?
wtc 2013/03/06 00:00:03 I will bring the book to the office tomorrow.
rvargas (doing something else) 2013/03/06 00:34:47 That's ok. We agree that it is better to add the c
Pat Meenan 2013/03/06 02:05:28 In theory the FD_CLOSE is supposed to stay signale
1030 read_callback_); 1030 os_error = network_events.iErrorCode[FD_READ_BIT];
1031 if (rv == ERR_IO_PENDING) 1031 rv = MapSystemError(os_error);
1032 return;
1033 } else if (network_events.lNetworkEvents & FD_CLOSE) {
1034 if (network_events.iErrorCode[FD_CLOSE_BIT]) {
1035 rv = MapSystemError(network_events.iErrorCode[FD_CLOSE_BIT]);
1036 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR, 1032 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR,
1037 CreateNetLogSocketErrorCallback(rv, os_error)); 1033 CreateNetLogSocketErrorCallback(rv, os_error));
wtc 2013/03/05 20:17:03 This is the bug. Note that we map network_events.i
1038 } else { 1034 } else {
1035 rv = DoRead(core_->read_iobuffer_, core_->read_buffer_length_,
1036 read_callback_);
1037 if (rv == ERR_IO_PENDING)
1038 return;
1039 }
1040 } else if (network_events.lNetworkEvents & FD_CLOSE) {
1041 DCHECK_EQ(network_events.lNetworkEvents & ~FD_CLOSE, 0);
1042 if (network_events.iErrorCode[FD_CLOSE_BIT]) {
1043 os_error = network_events.iErrorCode[FD_CLOSE_BIT];
1044 rv = MapSystemError(os_error);
1045 net_log_.AddEvent(NetLog::TYPE_SOCKET_READ_ERROR,
1046 CreateNetLogSocketErrorCallback(rv, os_error));
1047 } else {
1039 rv = 0; 1048 rv = 0;
1040 } 1049 }
1041 } else { 1050 } else {
1042 // This should not happen but I have seen cases where we will get 1051 // This should not happen but I have seen cases where we will get
1043 // signaled but the network events flags are all clear (0). 1052 // signaled but the network events flags are all clear (0).
1044 core_->WatchForRead(); 1053 core_->WatchForRead();
wtc 2013/03/05 20:17:03 I also saw this in my debugging. This occurs while
1045 return; 1054 return;
1046 } 1055 }
1047 waiting_read_ = false; 1056 waiting_read_ = false;
1048 core_->read_iobuffer_ = NULL; 1057 core_->read_iobuffer_ = NULL;
1049 core_->read_buffer_length_ = 0; 1058 core_->read_buffer_length_ = 0;
1050 DoReadCallback(rv); 1059 DoReadCallback(rv);
1051 } 1060 }
1052 1061
1053 } // namespace net 1062 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698