OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/base/tcp_client_socket_win.h" | 5 #include "net/base/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/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // In most socket implementations, closing a socket results in a graceful | 150 // In most socket implementations, closing a socket results in a graceful |
151 // connection shutdown, but in Winsock we have to call shutdown explicitly. | 151 // connection shutdown, but in Winsock we have to call shutdown explicitly. |
152 // See the MSDN page "Graceful Shutdown, Linger Options, and Socket Closure" | 152 // See the MSDN page "Graceful Shutdown, Linger Options, and Socket Closure" |
153 // at http://msdn.microsoft.com/en-us/library/ms738547.aspx | 153 // at http://msdn.microsoft.com/en-us/library/ms738547.aspx |
154 shutdown(socket_, SD_SEND); | 154 shutdown(socket_, SD_SEND); |
155 | 155 |
156 // This cancels any pending IO. | 156 // This cancels any pending IO. |
157 closesocket(socket_); | 157 closesocket(socket_); |
158 socket_ = INVALID_SOCKET; | 158 socket_ = INVALID_SOCKET; |
159 | 159 |
160 // Wait for pending IO to be aborted. | 160 if (waiting_read_ || waiting_write_) { |
161 if (waiting_read_) | 161 base::TimeTicks start = base::TimeTicks::Now(); |
162 WaitForSingleObject(read_overlapped_.hEvent, INFINITE); | 162 |
163 if (waiting_write_) | 163 // Wait for pending IO to be aborted. |
164 WaitForSingleObject(write_overlapped_.hEvent, INFINITE); | 164 if (waiting_read_) |
| 165 WaitForSingleObject(read_overlapped_.hEvent, INFINITE); |
| 166 if (waiting_write_) |
| 167 WaitForSingleObject(write_overlapped_.hEvent, INFINITE); |
| 168 |
| 169 // We want to see if we block the message loop for too long. |
| 170 UMA_HISTOGRAM_TIMES("AsyncIO.ClientSocketDisconnect", |
| 171 base::TimeTicks::Now() - start); |
| 172 } |
165 | 173 |
166 WSACloseEvent(read_overlapped_.hEvent); | 174 WSACloseEvent(read_overlapped_.hEvent); |
167 memset(&read_overlapped_, 0, sizeof(read_overlapped_)); | 175 memset(&read_overlapped_, 0, sizeof(read_overlapped_)); |
168 WSACloseEvent(write_overlapped_.hEvent); | 176 WSACloseEvent(write_overlapped_.hEvent); |
169 memset(&write_overlapped_, 0, sizeof(write_overlapped_)); | 177 memset(&write_overlapped_, 0, sizeof(write_overlapped_)); |
170 | 178 |
171 // Reset for next time. | 179 // Reset for next time. |
172 current_ai_ = addresses_.head(); | 180 current_ai_ = addresses_.head(); |
173 | 181 |
174 waiting_read_ = false; | 182 waiting_read_ = false; |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 FALSE, &flags); | 435 FALSE, &flags); |
428 WSAResetEvent(object); | 436 WSAResetEvent(object); |
429 TRACE_EVENT_END("socket.write", tcp_socket_, | 437 TRACE_EVENT_END("socket.write", tcp_socket_, |
430 StringPrintf("%d bytes", num_bytes)); | 438 StringPrintf("%d bytes", num_bytes)); |
431 tcp_socket_->waiting_write_ = false; | 439 tcp_socket_->waiting_write_ = false; |
432 tcp_socket_->DoWriteCallback( | 440 tcp_socket_->DoWriteCallback( |
433 ok ? num_bytes : MapWinsockError(WSAGetLastError())); | 441 ok ? num_bytes : MapWinsockError(WSAGetLastError())); |
434 } | 442 } |
435 | 443 |
436 } // namespace net | 444 } // namespace net |
OLD | NEW |