Index: net/base/tcp_listen_socket.h |
diff --git a/net/base/listen_socket.h b/net/base/tcp_listen_socket.h |
similarity index 59% |
copy from net/base/listen_socket.h |
copy to net/base/tcp_listen_socket.h |
index 8223767d548738559056aa42eb241009eaebba17..7f7fc50c03232b816601f3f9f301bb07dbcc328c 100644 |
--- a/net/base/listen_socket.h |
+++ b/net/base/tcp_listen_socket.h |
@@ -8,8 +8,8 @@ |
// 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_LISTEN_SOCKET_H_ |
-#define NET_BASE_LISTEN_SOCKET_H_ |
+#ifndef NET_BASE_TCP_LISTEN_SOCKET_H_ |
+#define NET_BASE_TCP_LISTEN_SOCKET_H_ |
#pragma once |
#include "build/build_config.h" |
@@ -26,7 +26,7 @@ |
#include "base/basictypes.h" |
#include "base/compiler_specific.h" |
-#include "base/memory/ref_counted.h" |
+#include "net/base/listen_socket.h" |
#include "net/base/net_export.h" |
#if defined(OS_POSIX) |
@@ -36,38 +36,17 @@ typedef int SOCKET; |
namespace net { |
// Implements a raw socket interface |
mmenke
2012/04/20 17:48:34
nit: Suggest you add a comment that this is ref c
Philippe
2012/04/23 09:28:22
Done.
|
-class NET_EXPORT ListenSocket : public base::RefCountedThreadSafe<ListenSocket>, |
+class NET_EXPORT TCPListenSocket : 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: |
- // TODO(erikkay): this delegate should really be split into two parts |
- // to split up the listener from the connected socket. Perhaps this class |
- // should be split up similarly. |
- class ListenSocketDelegate { |
- public: |
- virtual ~ListenSocketDelegate() {} |
- |
- // server is the original listening Socket, connection is the new |
- // Socket that was created. Ownership of connection is transferred |
- // to the delegate with this call. |
- virtual void DidAccept(ListenSocket *server, ListenSocket *connection) = 0; |
- virtual void DidRead(ListenSocket *connection, |
- const char* data, |
- int len) = 0; |
- virtual void DidClose(ListenSocket *sock) = 0; |
- }; |
- |
// Listen on port for the specified IP address. Use 127.0.0.1 to only |
// accept local connections. |
- static ListenSocket* Listen(std::string ip, int port, |
- ListenSocketDelegate* del); |
- |
- // Send data to the socket. |
- void Send(const char* bytes, int len, bool append_linefeed = false); |
- void Send(const std::string& str, bool append_linefeed = false); |
+ 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 |
@@ -76,8 +55,6 @@ class NET_EXPORT ListenSocket : public base::RefCountedThreadSafe<ListenSocket>, |
void ResumeReads(); |
protected: |
- friend class base::RefCountedThreadSafe<ListenSocket>; |
- |
enum WaitState { |
NOT_WAITING = 0, |
WAITING_ACCEPT = 1, |
@@ -87,13 +64,13 @@ class NET_EXPORT ListenSocket : public base::RefCountedThreadSafe<ListenSocket>, |
static const SOCKET kInvalidSocket; |
static const int kSocketError; |
- ListenSocket(SOCKET s, ListenSocketDelegate* del); |
- virtual ~ListenSocket(); |
- static SOCKET Listen(std::string ip, int port); |
+ 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); |
- virtual void SendInternal(const char* bytes, int len); |
+ virtual void SendInternal(const char* bytes, int len) OVERRIDE; |
mmenke
2012/04/20 17:48:34
nit: Add a comment that this is the implementatio
Philippe
2012/04/23 09:28:22
Done.
|
virtual void Listen(); |
virtual void Accept(); |
@@ -121,15 +98,14 @@ class NET_EXPORT ListenSocket : public base::RefCountedThreadSafe<ListenSocket>, |
#endif |
SOCKET socket_; |
- ListenSocketDelegate *socket_delegate_; |
private: |
bool reads_paused_; |
bool has_pending_reads_; |
- DISALLOW_COPY_AND_ASSIGN(ListenSocket); |
+ DISALLOW_COPY_AND_ASSIGN(TCPListenSocket); |
}; |
} // namespace net |
-#endif // NET_BASE_LISTEN_SOCKET_H_ |
+#endif // NET_BASE_TCP_LISTEN_SOCKET_H_ |