summaryrefslogtreecommitdiffstats
path: root/net/base/tcp_client_socket.h
diff options
context:
space:
mode:
authordkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-07 01:01:33 +0000
committerdkegel@google.com <dkegel@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-07 01:01:33 +0000
commit90594c625bd6ea7a2493cdda2c22f9352de14c97 (patch)
tree75d5d6c90d119689cd19239d509b4fce8fda485c /net/base/tcp_client_socket.h
parent99c8ead0d93839db506f86e0351ef7ea593f1890 (diff)
downloadchromium_src-90594c625bd6ea7a2493cdda2c22f9352de14c97.zip
chromium_src-90594c625bd6ea7a2493cdda2c22f9352de14c97.tar.gz
chromium_src-90594c625bd6ea7a2493cdda2c22f9352de14c97.tar.bz2
Reverting 7641.
Review URL: http://codereview.chromium.org/16563 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7643 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/tcp_client_socket.h')
-rw-r--r--net/base/tcp_client_socket.h65
1 files changed, 0 insertions, 65 deletions
diff --git a/net/base/tcp_client_socket.h b/net/base/tcp_client_socket.h
index 07d8351..5fca519 100644
--- a/net/base/tcp_client_socket.h
+++ b/net/base/tcp_client_socket.h
@@ -18,13 +18,9 @@ struct event; // From libevent
#endif
#include "base/scoped_ptr.h"
-#include "base/task.h"
-#include "base/thread.h"
-#include "base/waitable_event.h"
#include "net/base/address_list.h"
#include "net/base/client_socket.h"
#include "net/base/completion_callback.h"
-#include "net/base/net_errors.h"
namespace net {
@@ -131,67 +127,6 @@ class TCPClientSocket : public ClientSocket,
void DidCompleteConnect();
};
-// Tiny helper class to do a synchronous connect,
-// in lieu of directly supporting that in TcpClientSocket.
-// This avoids cluttering the main codepath with code only used by unit tests.
-// TODO(dkegel): move this to its own header file.
-class TCPClientSocketSyncConnector
- : public base::RefCounted<TCPClientSocketSyncConnector> {
- public:
- // Connect given socket synchronously.
- // Returns network error code.
- static int Connect(net::TCPClientSocket* sock) {
- // Start up a throwaway IO thread just for this.
- // TODO(port): use some existing thread pool instead?
- base::Thread io_thread("SyncConnect");
- base::Thread::Options options;
- options.message_loop_type = MessageLoop::TYPE_IO;
- io_thread.StartWithOptions(options);
-
- // Post a request to do the connect on that thread.
- scoped_refptr<TCPClientSocketSyncConnector> connector =
- new TCPClientSocketSyncConnector(sock);
- io_thread.message_loop()->PostTask(FROM_HERE, NewRunnableMethod(connector.get(),
- &net::TCPClientSocketSyncConnector::DoConnect));
- connector->Wait();
- return connector->GetError();
- }
-
- private:
- // Start a connect. Must be called on an IO thread.
- void DoConnect() {
- net_error_ = sock_->Connect(&connect_callback_);
- if (net_error_ != ERR_IO_PENDING)
- event_.Signal();
- }
-
- // Callback called on same IO thread when connection complete.
- void ConnectDone(int rv) {
- net_error_ = rv;
- event_.Signal();
- }
-
- // Call this after posting a call to DoConnect().
- void Wait() { event_.Wait(); }
-
- // Call this after Wait() if you need the final error code from the connect.
- int GetError() { return net_error_; }
-
- // sock is owned by caller, but must remain valid while this object lives.
- explicit TCPClientSocketSyncConnector(TCPClientSocket* sock) :
- event_(false, false),
- sock_(sock),
- net_error_(0),
- connect_callback_(this, &net::TCPClientSocketSyncConnector::ConnectDone) {
- }
-
- base::WaitableEvent event_;
- net::TCPClientSocket* sock_;
- int net_error_;
- net::CompletionCallbackImpl<TCPClientSocketSyncConnector> connect_callback_;
- DISALLOW_COPY_AND_ASSIGN(TCPClientSocketSyncConnector);
-};
-
} // namespace net
#endif // NET_BASE_TCP_CLIENT_SOCKET_H_