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

Unified Diff: net/base/default_listen_socket.h

Issue 10161005: Add DefaultListenSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix year in license header 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/base/listen_socket.h » ('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 61%
copy from net/base/tcp_listen_socket.h
copy to net/base/default_listen_socket.h
index 57d467901b54228915de437a3ab5d04350d792ec..6dcc4829befe1f14c1630edc49a0da6ec647df19 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
mmenke 2012/04/25 17:25:31 Default isn't really an accurate description, or a
Philippe 2012/04/30 06:55:21 Indeed.
+// 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 TCP socket interface. Note that this is ref counted.
-class NET_EXPORT TCPListenSocket : public ListenSocket,
+class NET_EXPORT DefaultListenSocket
mmenke 2012/04/25 17:25:31 Suggest you call this ListenSocketBase. It has tw
mmenke 2012/04/25 17:25:31 Are there any plans to make any other direct subcl
Philippe 2012/04/30 06:55:21 I liked StreamListenSocket.
Philippe 2012/04/30 06:55:21 I don't think so. I guess that your underlying sug
mmenke 2012/04/30 19:11:44 Yea, I was wondering if there was any need for it.
+ : 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:
mmenke 2012/04/25 17:25:31 nit: Please add a blank line above the "protected
Philippe 2012/04/30 06:55:21 Done.
enum WaitState {
NOT_WAITING = 0,
@@ -64,17 +55,16 @@ 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
+ DefaultListenSocket(SOCKET s, ListenSocketDelegate* del);
+ virtual ~DefaultListenSocket();
+
static SOCKET Accept(SOCKET s);
mmenke 2012/04/25 17:25:31 There doesn't seem to be any reason to make the cu
mmenke 2012/04/25 17:27:20 Just to clarify, as a non-static function, it woul
Philippe 2012/04/30 06:55:21 Good point.
// Implements ListenSocket::SendInternal.
virtual void SendInternal(const char* bytes, int len) OVERRIDE;
virtual void Listen();
mmenke 2012/04/25 17:25:31 It looks to me like Listen, Read, Close, and Close
Philippe 2012/04/30 06:55:21 Done.
- virtual void Accept();
+ virtual void AcceptInternal() = 0;
mmenke 2012/04/25 17:25:31 This naming seems a little weird. SendInternal is
Philippe 2012/04/30 06:55:21 Done.
virtual void Read();
virtual void Close();
virtual void CloseSocket(SOCKET s);
@@ -98,15 +88,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;
mmenke 2012/04/25 17:25:31 nit: Please add a linebreak between the friend de
Philippe 2012/04/30 06:55:21 Done.
+ 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/base/listen_socket.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698