summaryrefslogtreecommitdiffstats
path: root/net/socket
diff options
context:
space:
mode:
authorwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-25 02:17:56 +0000
committerwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-25 02:17:56 +0000
commit62755f824d5d77d0d110d3cc4e3f7614632e29ee (patch)
treef328efdc69b6c022084e5f6be5f3a42a17088a8a /net/socket
parent33c141aefc29ca5523cb2d462835969b6b3a5bf3 (diff)
downloadchromium_src-62755f824d5d77d0d110d3cc4e3f7614632e29ee.zip
chromium_src-62755f824d5d77d0d110d3cc4e3f7614632e29ee.tar.gz
chromium_src-62755f824d5d77d0d110d3cc4e3f7614632e29ee.tar.bz2
TCPServerSocketLibevent should call StopWatchingFileDescriptor()
when Accept() completes asynchronously (because Accept() calls WatchFileDescriptor() in persistent mode) or before it closes socket_. This matches what TCPClientSocketLibevent does. Without this fix, the TCPServerSocketTest.Accept2Connections unit test may crash in accept_callback.WaitForResult() for some message loop scheduling policies because two connections are ready to be accepted but only one accept_socket_ is provided. Fix a comment typo in object_watcher.h. Avoid a redundant StopWatchingFileDescriptor call in TCPClientSocketLibevent. R=sergeyu@chromium.org,willchan@chromium.org BUG=none TEST=covered by existing unit tests Review URL: http://codereview.chromium.org/7239018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90476 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket')
-rw-r--r--net/socket/tcp_client_socket_libevent.cc3
-rw-r--r--net/socket/tcp_server_socket_libevent.cc4
2 files changed, 5 insertions, 2 deletions
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc
index 38c3446..3c5ec13 100644
--- a/net/socket/tcp_client_socket_libevent.cc
+++ b/net/socket/tcp_client_socket_libevent.cc
@@ -336,9 +336,8 @@ int TCPClientSocketLibevent::DoConnectComplete(int result) {
params = new NetLogIntegerParameter("os_error", os_error);
net_log_.EndEvent(NetLog::TYPE_TCP_CONNECT_ATTEMPT, params);
- write_socket_watcher_.StopWatchingFileDescriptor();
-
if (result == OK) {
+ write_socket_watcher_.StopWatchingFileDescriptor();
use_history_.set_was_ever_connected();
return OK; // Done!
}
diff --git a/net/socket/tcp_server_socket_libevent.cc b/net/socket/tcp_server_socket_libevent.cc
index 02c448a..3e25fab 100644
--- a/net/socket/tcp_server_socket_libevent.cc
+++ b/net/socket/tcp_server_socket_libevent.cc
@@ -172,6 +172,8 @@ int TCPServerSocketLibevent::AcceptInternal(
void TCPServerSocketLibevent::Close() {
if (socket_ != kInvalidSocket) {
+ bool ok = accept_socket_watcher_.StopWatchingFileDescriptor();
+ DCHECK(ok);
if (HANDLE_EINTR(close(socket_)) < 0)
PLOG(ERROR) << "close";
socket_ = kInvalidSocket;
@@ -186,6 +188,8 @@ void TCPServerSocketLibevent::OnFileCanReadWithoutBlocking(int fd) {
CompletionCallback* c = accept_callback_;
accept_callback_ = NULL;
accept_socket_ = NULL;
+ bool ok = accept_socket_watcher_.StopWatchingFileDescriptor();
+ DCHECK(ok);
c->Run(result);
}
}