diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-26 00:32:16 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-26 00:32:16 +0000 |
commit | 5892dbea4f6dcc325fa48e963f63feffaed6eb2e (patch) | |
tree | 44d85457255d8d3c40d0c3bb6600045deed9f391 /net/base/tcp_client_socket_win.cc | |
parent | 9045ff8b748950d11f5c750cbf59e56606e80ec5 (diff) | |
download | chromium_src-5892dbea4f6dcc325fa48e963f63feffaed6eb2e.zip chromium_src-5892dbea4f6dcc325fa48e963f63feffaed6eb2e.tar.gz chromium_src-5892dbea4f6dcc325fa48e963f63feffaed6eb2e.tar.bz2 |
Don't use CancelIo to cancel pending IO before closing a
socket because CancelIo doesn't work when there is a Winsock
layered service provider.
R=rvargas,darin
BUG=9258
TEST=Doing web searches from the Omnibox will exercise the
code. Clicking a link on a page that is still loading will
also exercise the code. The browser should stay responsive.
Review URL: http://codereview.chromium.org/99025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14551 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/tcp_client_socket_win.cc')
-rw-r--r-- | net/base/tcp_client_socket_win.cc | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/net/base/tcp_client_socket_win.cc b/net/base/tcp_client_socket_win.cc index f0e9674..54eb49f 100644 --- a/net/base/tcp_client_socket_win.cc +++ b/net/base/tcp_client_socket_win.cc @@ -144,14 +144,8 @@ void TCPClientSocketWin::Disconnect() { read_watcher_.StopWatching(); write_watcher_.StopWatching(); - // Cancel any pending IO and wait for it to be aborted. - if (waiting_read_ || waiting_write_) { - CancelIo(reinterpret_cast<HANDLE>(socket_)); - if (waiting_read_) - WaitForSingleObject(read_overlapped_.hEvent, INFINITE); - if (waiting_write_) - WaitForSingleObject(write_overlapped_.hEvent, INFINITE); - } + // Note: don't use CancelIo to cancel pending IO because it doesn't work + // when there is a Winsock layered service provider. // In most socket implementations, closing a socket results in a graceful // connection shutdown, but in Winsock we have to call shutdown explicitly. @@ -159,9 +153,16 @@ void TCPClientSocketWin::Disconnect() { // at http://msdn.microsoft.com/en-us/library/ms738547.aspx shutdown(socket_, SD_SEND); + // This cancels any pending IO. closesocket(socket_); socket_ = INVALID_SOCKET; + // Wait for pending IO to be aborted. + if (waiting_read_) + WaitForSingleObject(read_overlapped_.hEvent, INFINITE); + if (waiting_write_) + WaitForSingleObject(write_overlapped_.hEvent, INFINITE); + WSACloseEvent(read_overlapped_.hEvent); memset(&read_overlapped_, 0, sizeof(read_overlapped_)); WSACloseEvent(write_overlapped_.hEvent); @@ -213,8 +214,8 @@ int TCPClientSocketWin::Read(char* buf, DCHECK(!waiting_read_); DCHECK(!read_callback_); - read_buffer_.len = buf_len; - read_buffer_.buf = buf; + read_buffer_.len = buf_len; + read_buffer_.buf = buf; TRACE_EVENT_BEGIN("socket.read", this, ""); // TODO(wtc): Remove the CHECK after enough testing. |