diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-19 22:17:08 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-19 22:17:08 +0000 |
commit | 94f808c3eaa95d3bc66be0c7caa66f37d9e0cbae (patch) | |
tree | ebc3916995102d43a2c60b9d8158fe362a37a77b /net/socket | |
parent | 564261db36338330d9b4b046e4a386b6e99ba10a (diff) | |
download | chromium_src-94f808c3eaa95d3bc66be0c7caa66f37d9e0cbae.zip chromium_src-94f808c3eaa95d3bc66be0c7caa66f37d9e0cbae.tar.gz chromium_src-94f808c3eaa95d3bc66be0c7caa66f37d9e0cbae.tar.bz2 |
Make TCPClientSocket* inherit from NonThreadSafe.
Review URL: http://codereview.chromium.org/2108022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47735 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket')
-rw-r--r-- | net/socket/tcp_client_socket_libevent.cc | 13 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_libevent.h | 3 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_win.cc | 13 | ||||
-rw-r--r-- | net/socket/tcp_client_socket_win.h | 3 |
4 files changed, 30 insertions, 2 deletions
diff --git a/net/socket/tcp_client_socket_libevent.cc b/net/socket/tcp_client_socket_libevent.cc index 98f32d41..92d2560 100644 --- a/net/socket/tcp_client_socket_libevent.cc +++ b/net/socket/tcp_client_socket_libevent.cc @@ -125,6 +125,8 @@ TCPClientSocketLibevent::~TCPClientSocketLibevent() { } int TCPClientSocketLibevent::Connect(CompletionCallback* callback) { + DCHECK(CalledOnValidThread()); + // If already connected, then just return OK. if (socket_ != kInvalidSocket) return OK; @@ -230,6 +232,8 @@ int TCPClientSocketLibevent::DoConnectComplete(int result) { } void TCPClientSocketLibevent::Disconnect() { + DCHECK(CalledOnValidThread()); + DoDisconnect(); current_ai_ = NULL; } @@ -247,6 +251,8 @@ void TCPClientSocketLibevent::DoDisconnect() { } bool TCPClientSocketLibevent::IsConnected() const { + DCHECK(CalledOnValidThread()); + if (socket_ == kInvalidSocket || waiting_connect()) return false; @@ -262,6 +268,8 @@ bool TCPClientSocketLibevent::IsConnected() const { } bool TCPClientSocketLibevent::IsConnectedAndIdle() const { + DCHECK(CalledOnValidThread()); + if (socket_ == kInvalidSocket || waiting_connect()) return false; @@ -280,6 +288,7 @@ bool TCPClientSocketLibevent::IsConnectedAndIdle() const { int TCPClientSocketLibevent::Read(IOBuffer* buf, int buf_len, CompletionCallback* callback) { + DCHECK(CalledOnValidThread()); DCHECK_NE(kInvalidSocket, socket_); DCHECK(!waiting_connect()); DCHECK(!read_callback_); @@ -316,6 +325,7 @@ int TCPClientSocketLibevent::Read(IOBuffer* buf, int TCPClientSocketLibevent::Write(IOBuffer* buf, int buf_len, CompletionCallback* callback) { + DCHECK(CalledOnValidThread()); DCHECK_NE(kInvalidSocket, socket_); DCHECK(!waiting_connect()); DCHECK(!write_callback_); @@ -348,6 +358,7 @@ int TCPClientSocketLibevent::Write(IOBuffer* buf, } bool TCPClientSocketLibevent::SetReceiveBufferSize(int32 size) { + DCHECK(CalledOnValidThread()); int rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<const char*>(&size), sizeof(size)); @@ -356,6 +367,7 @@ bool TCPClientSocketLibevent::SetReceiveBufferSize(int32 size) { } bool TCPClientSocketLibevent::SetSendBufferSize(int32 size) { + DCHECK(CalledOnValidThread()); int rv = setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char*>(&size), sizeof(size)); @@ -475,6 +487,7 @@ void TCPClientSocketLibevent::DidCompleteWrite() { } int TCPClientSocketLibevent::GetPeerAddress(AddressList* address) const { + DCHECK(CalledOnValidThread()); DCHECK(address); if (!current_ai_) return ERR_UNEXPECTED; diff --git a/net/socket/tcp_client_socket_libevent.h b/net/socket/tcp_client_socket_libevent.h index 6186159..48557d0 100644 --- a/net/socket/tcp_client_socket_libevent.h +++ b/net/socket/tcp_client_socket_libevent.h @@ -6,6 +6,7 @@ #define NET_SOCKET_TCP_CLIENT_SOCKET_LIBEVENT_H_ #include "base/message_loop.h" +#include "base/non_thread_safe.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "net/base/address_list.h" @@ -20,7 +21,7 @@ namespace net { class BoundNetLog; // A client socket that uses TCP as the transport layer. -class TCPClientSocketLibevent : public ClientSocket { +class TCPClientSocketLibevent : public ClientSocket, NonThreadSafe { public: // The IP address(es) and port number to connect to. The TCP socket will try // each IP address in the list until it succeeds in establishing a diff --git a/net/socket/tcp_client_socket_win.cc b/net/socket/tcp_client_socket_win.cc index fffc37a..a24a313 100644 --- a/net/socket/tcp_client_socket_win.cc +++ b/net/socket/tcp_client_socket_win.cc @@ -292,6 +292,8 @@ TCPClientSocketWin::~TCPClientSocketWin() { } int TCPClientSocketWin::Connect(CompletionCallback* callback) { + DCHECK(CalledOnValidThread()); + // If already connected, then just return OK. if (socket_ != INVALID_SOCKET) return OK; @@ -368,6 +370,8 @@ int TCPClientSocketWin::DoConnect() { } void TCPClientSocketWin::Disconnect() { + DCHECK(CalledOnValidThread()); + if (socket_ == INVALID_SOCKET) return; @@ -406,6 +410,8 @@ void TCPClientSocketWin::Disconnect() { } bool TCPClientSocketWin::IsConnected() const { + DCHECK(CalledOnValidThread()); + if (socket_ == INVALID_SOCKET || waiting_connect_) return false; @@ -421,6 +427,8 @@ bool TCPClientSocketWin::IsConnected() const { } bool TCPClientSocketWin::IsConnectedAndIdle() const { + DCHECK(CalledOnValidThread()); + if (socket_ == INVALID_SOCKET || waiting_connect_) return false; @@ -437,6 +445,7 @@ bool TCPClientSocketWin::IsConnectedAndIdle() const { } int TCPClientSocketWin::GetPeerAddress(AddressList* address) const { + DCHECK(CalledOnValidThread()); DCHECK(address); if (!current_ai_) return ERR_FAILED; @@ -447,6 +456,7 @@ int TCPClientSocketWin::GetPeerAddress(AddressList* address) const { int TCPClientSocketWin::Read(IOBuffer* buf, int buf_len, CompletionCallback* callback) { + DCHECK(CalledOnValidThread()); DCHECK_NE(socket_, INVALID_SOCKET); DCHECK(!waiting_read_); DCHECK(!read_callback_); @@ -496,6 +506,7 @@ int TCPClientSocketWin::Read(IOBuffer* buf, int TCPClientSocketWin::Write(IOBuffer* buf, int buf_len, CompletionCallback* callback) { + DCHECK(CalledOnValidThread()); DCHECK_NE(socket_, INVALID_SOCKET); DCHECK(!waiting_write_); DCHECK(!write_callback_); @@ -546,6 +557,7 @@ int TCPClientSocketWin::Write(IOBuffer* buf, } bool TCPClientSocketWin::SetReceiveBufferSize(int32 size) { + DCHECK(CalledOnValidThread()); int rv = setsockopt(socket_, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<const char*>(&size), sizeof(size)); DCHECK(!rv) << "Could not set socket receive buffer size: " << GetLastError(); @@ -553,6 +565,7 @@ bool TCPClientSocketWin::SetReceiveBufferSize(int32 size) { } bool TCPClientSocketWin::SetSendBufferSize(int32 size) { + DCHECK(CalledOnValidThread()); int rv = setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<const char*>(&size), sizeof(size)); DCHECK(!rv) << "Could not set socket send buffer size: " << GetLastError(); diff --git a/net/socket/tcp_client_socket_win.h b/net/socket/tcp_client_socket_win.h index 7e4eb8f..d1a2148 100644 --- a/net/socket/tcp_client_socket_win.h +++ b/net/socket/tcp_client_socket_win.h @@ -7,6 +7,7 @@ #include <winsock2.h> +#include "base/non_thread_safe.h" #include "base/object_watcher.h" #include "net/base/address_list.h" #include "net/base/completion_callback.h" @@ -17,7 +18,7 @@ namespace net { class BoundNetLog; -class TCPClientSocketWin : public ClientSocket { +class TCPClientSocketWin : public ClientSocket, NonThreadSafe { public: // The IP address(es) and port number to connect to. The TCP socket will try // each IP address in the list until it succeeds in establishing a |