Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1751)

Unified Diff: net/base/default_listen_socket.h

Issue 10161005: Add DefaultListenSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/base/default_listen_socket.cc » ('j') | net/socket/transport_client_socket_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/default_listen_socket.h
diff --git a/net/base/tcp_listen_socket.h b/net/base/default_listen_socket.h
similarity index 60%
copy from net/base/tcp_listen_socket.h
copy to net/base/default_listen_socket.h
index c13b8a48740993b2bc068dfcfb35f4fa5c960919..475417abf18637d14418ff8b1d65446a8b1716c8 100644
--- a/net/base/tcp_listen_socket.h
+++ b/net/base/default_listen_socket.h
@@ -2,14 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// TCP/IP server that handles IO asynchronously in the specified MessageLoop.
-// These objects are NOT thread safe. They use WSAEVENT handles to monitor
-// activity in a given MessageLoop. This means that callbacks will
-// happen in that loop's thread always and that all other methods (including
-// constructors and destructors) should also be called from the same thread.
-
-#ifndef NET_BASE_TCP_LISTEN_SOCKET_H_
-#define NET_BASE_TCP_LISTEN_SOCKET_H_
+// Default (abstract) listen socket implementation that can be used by clients
+// to implement more specific classes like TCPListenSocket and UnixDomainSocket.
+
+// Server that handles IO asynchronously in the specified MessageLoop. These
+// objects are NOT thread safe. They use WSAEVENT handles to monitor activity
+// in a given MessageLoop. This means that callbacks will happen in that loop's
+// thread always and that all other methods (including constructors and
+// destructors) should also be called from the same thread.
+
+#ifndef NET_BASE_DEFAULT_LISTEN_SOCKET_H_
+#define NET_BASE_DEFAULT_LISTEN_SOCKET_H_
#pragma once
#include "build/build_config.h"
@@ -35,25 +38,13 @@ typedef int SOCKET;
namespace net {
-// Implements a raw socket interface
-class NET_EXPORT TCPListenSocket : public ListenSocket,
+class NET_EXPORT DefaultListenSocket
+ : public ListenSocket,
#if defined(OS_WIN)
- public base::win::ObjectWatcher::Delegate {
+ public base::win::ObjectWatcher::Delegate {
#elif defined(OS_POSIX)
- public MessageLoopForIO::Watcher {
+ public MessageLoopForIO::Watcher {
#endif
- public:
- // Listen on port for the specified IP address. Use 127.0.0.1 to only
- // accept local connections.
- static TCPListenSocket* CreateAndListen(std::string ip, int port,
- ListenSocketDelegate* del);
-
- // NOTE: This is for unit test use only!
- // Pause/Resume calling Read(). Note that ResumeReads() will also call
- // Read() if there is anything to read.
- void PauseReads();
- void ResumeReads();
-
protected:
enum WaitState {
NOT_WAITING = 0,
@@ -64,16 +55,15 @@ class NET_EXPORT TCPListenSocket : public ListenSocket,
static const SOCKET kInvalidSocket;
static const int kSocketError;
- TCPListenSocket(SOCKET s, ListenSocketDelegate* del);
- virtual ~TCPListenSocket();
- static SOCKET CreateAndBind(std::string ip, int port);
- // if valid, returned SOCKET is non-blocking
- static SOCKET Accept(SOCKET s);
+ DefaultListenSocket(SOCKET s, ListenSocketDelegate* del);
+ virtual ~DefaultListenSocket();
+
+ static SOCKET AcceptInternal(SOCKET s);
virtual void SendInternal(const char* bytes, int len) OVERRIDE;
virtual void Listen();
- virtual void Accept();
+ virtual void Accept() = 0;
virtual void Read();
virtual void Close();
virtual void CloseSocket(SOCKET s);
@@ -97,15 +87,22 @@ class NET_EXPORT TCPListenSocket : public ListenSocket,
MessageLoopForIO::FileDescriptorWatcher watcher_;
#endif
- SOCKET socket_;
+ const SOCKET socket_;
private:
+ // NOTE: This is for unit test use only!
+ // Pause/Resume calling Read(). Note that ResumeReads() will also call
+ // Read() if there is anything to read.
+ friend class TransportClientSocketTest;
+ void PauseReads();
+ void ResumeReads();
+
bool reads_paused_;
bool has_pending_reads_;
- DISALLOW_COPY_AND_ASSIGN(TCPListenSocket);
+ DISALLOW_COPY_AND_ASSIGN(DefaultListenSocket);
};
} // namespace net
-#endif // NET_BASE_TCP_LISTEN_SOCKET_H_
+#endif // NET_BASE_DEFAULT_LISTEN_SOCKET_H_
« no previous file with comments | « no previous file | net/base/default_listen_socket.cc » ('j') | net/socket/transport_client_socket_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698