From 5656af67903d044c131bc07ebf41e0fc20bf1f29 Mon Sep 17 00:00:00 2001 From: "wtc@google.com" Date: Thu, 14 Aug 2008 22:55:04 +0000 Subject: Update the comment for OnObjectSignaled. The event object for the completion of overlapped I/O is also set when WSARecv or WSASend returns 0, so we need to reset the event object in that case. Add temporary debugging code to assert that the event object is in the expected state before and after WSARecv and WSASend calls. R=darin git-svn-id: svn://svn.chromium.org/chrome/trunk/src@906 0039d316-1c4b-4281-b951-d872f2087c98 --- net/base/tcp_client_socket.cc | 26 ++++++++++++++++++++------ net/base/tcp_client_socket.h | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'net') diff --git a/net/base/tcp_client_socket.cc b/net/base/tcp_client_socket.cc index cef7ef2..e2a4a2a 100644 --- a/net/base/tcp_client_socket.cc +++ b/net/base/tcp_client_socket.cc @@ -175,17 +175,24 @@ int TCPClientSocket::Read(char* buf, buffer_.len = buf_len; buffer_.buf = buf; + // TODO(wtc): Remove the CHECKs after enough testing. + CHECK(WaitForSingleObject(overlapped_.hEvent, 0) == WAIT_TIMEOUT); DWORD num, flags = 0; int rv = WSARecv(socket_, &buffer_, 1, &num, &flags, &overlapped_, NULL); - if (rv == 0) + if (rv == 0) { + CHECK(WaitForSingleObject(overlapped_.hEvent, 0) == WAIT_OBJECT_0); + BOOL ok = WSAResetEvent(overlapped_.hEvent); + CHECK(ok); return static_cast(num); - if (rv == SOCKET_ERROR && WSAGetLastError() == WSA_IO_PENDING) { + } + int err = WSAGetLastError(); + if (err == WSA_IO_PENDING) { watcher_.StartWatching(overlapped_.hEvent, this); wait_state_ = WAITING_READ; callback_ = callback; return ERR_IO_PENDING; } - return MapWinsockError(WSAGetLastError()); + return MapWinsockError(err); } int TCPClientSocket::Write(const char* buf, @@ -198,17 +205,24 @@ int TCPClientSocket::Write(const char* buf, buffer_.len = buf_len; buffer_.buf = const_cast(buf); + // TODO(wtc): Remove the CHECKs after enough testing. + CHECK(WaitForSingleObject(overlapped_.hEvent, 0) == WAIT_TIMEOUT); DWORD num; int rv = WSASend(socket_, &buffer_, 1, &num, 0, &overlapped_, NULL); - if (rv == 0) + if (rv == 0) { + CHECK(WaitForSingleObject(overlapped_.hEvent, 0) == WAIT_OBJECT_0); + BOOL ok = WSAResetEvent(overlapped_.hEvent); + CHECK(ok); return static_cast(num); - if (rv == SOCKET_ERROR && WSAGetLastError() == WSA_IO_PENDING) { + } + int err = WSAGetLastError(); + if (err == WSA_IO_PENDING) { watcher_.StartWatching(overlapped_.hEvent, this); wait_state_ = WAITING_WRITE; callback_ = callback; return ERR_IO_PENDING; } - return MapWinsockError(WSAGetLastError()); + return MapWinsockError(err); } int TCPClientSocket::CreateSocket(const struct addrinfo* ai) { diff --git a/net/base/tcp_client_socket.h b/net/base/tcp_client_socket.h index 3885026..57960c9 100644 --- a/net/base/tcp_client_socket.h +++ b/net/base/tcp_client_socket.h @@ -68,7 +68,7 @@ class TCPClientSocket : public ClientSocket, void DidCompleteConnect(); void DidCompleteIO(); - // MessageLoop::Watcher methods: + // base::ObjectWatcher::Delegate methods: virtual void OnObjectSignaled(HANDLE object); SOCKET socket_; -- cgit v1.1