Index: net/socket/server_socket.h |
diff --git a/net/socket/server_socket.h b/net/socket/server_socket.h |
index 11151eea1539636928b64aee65876dfacd9e60ec..ad1af018f5c83967d76bb2fe02086c838c91a0f0 100644 |
--- a/net/socket/server_socket.h |
+++ b/net/socket/server_socket.h |
@@ -7,26 +7,26 @@ |
#include "base/memory/scoped_ptr.h" |
#include "net/base/completion_callback.h" |
+#include "net/base/ip_endpoint.h" |
#include "net/base/net_export.h" |
namespace net { |
-class IPEndPoint; |
class StreamSocket; |
class NET_EXPORT ServerSocket { |
public: |
- ServerSocket() { } |
- virtual ~ServerSocket() { } |
+ ServerSocket() {} |
+ virtual ~ServerSocket() {} |
- // Bind the socket and start listening. Destroy the socket to stop |
+ // Binds the socket and start listening. Destroy the socket to stop |
// listening. |
virtual int Listen(const net::IPEndPoint& address, int backlog) = 0; |
// Gets current address the socket is bound to. |
virtual int GetLocalAddress(IPEndPoint* address) const = 0; |
- // Accept connection. Callback is called when new connection is |
+ // Accepts connection. Callback is called when new connection is |
// accepted. |
virtual int Accept(scoped_ptr<StreamSocket>* socket, |
const CompletionCallback& callback) = 0; |
@@ -35,6 +35,36 @@ class NET_EXPORT ServerSocket { |
DISALLOW_COPY_AND_ASSIGN(ServerSocket); |
}; |
+class NET_EXPORT ServerSocketFactory { |
+ public: |
+ ServerSocketFactory(); |
+ virtual ~ServerSocketFactory(); |
+ |
+ // Returns a new instance of ServerSocket or NULL if an error occurred. |
+ // It calls ServerSocket::Listen() with address and backlog set previously. |
+ // Subclasses may override this function if ServerSocket::Listen() is not a |
+ // right behavior. |
+ virtual scoped_ptr<ServerSocket> CreateAndListen() const; |
+ |
+ void set_address(const IPEndPoint& address) { address_ = address; } |
+ void set_backlog(int backlog) { backlog_ = backlog; } |
+ |
+ // Sets address with string representation and port. It expects a vaild |
+ // IPv4 or IPv6 address. Otherwise, it returns false. |
+ bool SetAddressAndPort(const std::string& address_string, int port); |
+ |
+ protected: |
+ // Creates a server socket. ServerSocket::Listen() will be called soon unless |
+ // it returns NULL. |
+ virtual scoped_ptr<ServerSocket> Create() const = 0; |
+ |
+ private: |
+ IPEndPoint address_; |
+ int backlog_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ServerSocketFactory); |
+}; |
+ |
} // namespace net |
#endif // NET_SOCKET_SERVER_SOCKET_H_ |