summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authorwtc@google.com <wtc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-20 18:17:05 +0000
committerwtc@google.com <wtc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-20 18:17:05 +0000
commitad9038cc39cc14dc420c9ca9aead30f43195102a (patch)
tree7c868febe3997988b6d82ac36d21d62e192e2088 /net/base
parent73d63714f99c96a67064599764b0d8210f52878e (diff)
downloadchromium_src-ad9038cc39cc14dc420c9ca9aead30f43195102a.zip
chromium_src-ad9038cc39cc14dc420c9ca9aead30f43195102a.tar.gz
chromium_src-ad9038cc39cc14dc420c9ca9aead30f43195102a.tar.bz2
Cancel any pending IO and wait for it to be aborted before
returning from the Disconnect method. This allows the caller to destroy the read or write buffer safely when the destructor (which calls Disconnect) returns. R=eroman,rvargas BUG=4449 Review URL: http://codereview.chromium.org/11299 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5775 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/tcp_client_socket_win.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/net/base/tcp_client_socket_win.cc b/net/base/tcp_client_socket_win.cc
index bb25e34..11a6de3 100644
--- a/net/base/tcp_client_socket_win.cc
+++ b/net/base/tcp_client_socket_win.cc
@@ -79,6 +79,7 @@ int TCPClientSocket::Connect(CompletionCallback* callback) {
if (rv != OK)
return rv;
+ // WSACreateEvent creates a manual-reset event object.
overlapped_.hEvent = WSACreateEvent();
// WSAEventSelect sets the socket to non-blocking mode as a side effect.
// Our connect() and recv() calls require that the socket be non-blocking.
@@ -116,13 +117,19 @@ void TCPClientSocket::Disconnect() {
// Make sure the message loop is not watching this object anymore.
watcher_.StopWatching();
+ // Cancel any pending IO and wait for it to be aborted.
+ if (wait_state_ == WAITING_READ || wait_state_ == WAITING_WRITE) {
+ CancelIo(reinterpret_cast<HANDLE>(socket_));
+ WaitForSingleObject(overlapped_.hEvent, INFINITE);
+ wait_state_ = NOT_WAITING;
+ }
+
// In most socket implementations, closing a socket results in a graceful
// connection shutdown, but in Winsock we have to call shutdown explicitly.
// See the MSDN page "Graceful Shutdown, Linger Options, and Socket Closure"
// at http://msdn.microsoft.com/en-us/library/ms738547.aspx
shutdown(socket_, SD_SEND);
- // This cancels any pending IO.
closesocket(socket_);
socket_ = INVALID_SOCKET;