OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_SOCKET_SERVER_SOCKET_H_ | 5 #ifndef NET_SOCKET_SERVER_SOCKET_H_ |
6 #define NET_SOCKET_SERVER_SOCKET_H_ | 6 #define NET_SOCKET_SERVER_SOCKET_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
10 #include "net/base/ip_endpoint.h" | |
10 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
11 | 12 |
12 namespace net { | 13 namespace net { |
13 | 14 |
14 class IPEndPoint; | |
15 class StreamSocket; | 15 class StreamSocket; |
16 | 16 |
17 class NET_EXPORT ServerSocket { | 17 class NET_EXPORT ServerSocket { |
18 public: | 18 public: |
19 ServerSocket() { } | 19 ServerSocket() {} |
20 virtual ~ServerSocket() { } | 20 virtual ~ServerSocket() {} |
21 | 21 |
22 // Bind the socket and start listening. Destroy the socket to stop | 22 // Binds the socket and start listening. Destroy the socket to stop |
23 // listening. | 23 // listening. |
24 virtual int Listen(const net::IPEndPoint& address, int backlog) = 0; | 24 virtual int Listen(const net::IPEndPoint& address, int backlog) = 0; |
25 | 25 |
26 // Gets current address the socket is bound to. | 26 // Gets current address the socket is bound to. |
27 virtual int GetLocalAddress(IPEndPoint* address) const = 0; | 27 virtual int GetLocalAddress(IPEndPoint* address) const = 0; |
28 | 28 |
29 // Accept connection. Callback is called when new connection is | 29 // Accepts connection. Callback is called when new connection is |
30 // accepted. | 30 // accepted. |
31 virtual int Accept(scoped_ptr<StreamSocket>* socket, | 31 virtual int Accept(scoped_ptr<StreamSocket>* socket, |
32 const CompletionCallback& callback) = 0; | 32 const CompletionCallback& callback) = 0; |
33 | 33 |
34 private: | 34 private: |
35 DISALLOW_COPY_AND_ASSIGN(ServerSocket); | 35 DISALLOW_COPY_AND_ASSIGN(ServerSocket); |
36 }; | 36 }; |
37 | 37 |
38 class NET_EXPORT ServerSocketFactory { | |
mmenke
2014/06/04 16:29:50
What's the motivation behind adding this class?
byungchul
2014/06/04 17:41:28
Devtools builds a socket factory class in UI threa
mmenke
2014/06/04 21:00:00
Hrm...Wonder if it makes more sense to make this D
byungchul
2014/06/06 19:17:35
Done.
| |
39 public: | |
40 ServerSocketFactory(); | |
41 virtual ~ServerSocketFactory(); | |
42 | |
43 // Returns a new instance of ServerSocket or NULL if an error occurred. | |
44 // It calls ServerSocket::Listen() with address and backlog set previously. | |
45 // Subclasses may override this function if ServerSocket::Listen() is not a | |
46 // right behavior. | |
mmenke
2014/06/04 16:29:50
nit: "a right behavior" -> "the right behavior"
byungchul
2014/06/06 19:17:35
Done.
| |
47 virtual scoped_ptr<ServerSocket> CreateAndListen() const; | |
48 | |
49 void set_address(const IPEndPoint& address) { address_ = address; } | |
mmenke
2014/06/04 16:29:50
It seems odd to me that this isn't an argument to
byungchul
2014/06/04 17:41:28
Again, setting address and calling CreateAndListen
| |
50 void set_backlog(int backlog) { backlog_ = backlog; } | |
mmenke
2014/06/04 16:29:50
These should be documented.
byungchul
2014/06/06 19:17:35
Removed and they are passed to constructor.
| |
51 | |
52 // Sets address with string representation and port. It expects a vaild | |
53 // IPv4 or IPv6 address. Otherwise, it returns false. | |
54 bool SetAddressAndPort(const std::string& address_string, int port); | |
55 | |
56 protected: | |
57 // Creates a server socket. ServerSocket::Listen() will be called soon unless | |
58 // it returns NULL. | |
59 virtual scoped_ptr<ServerSocket> Create() const = 0; | |
60 | |
61 private: | |
62 IPEndPoint address_; | |
63 int backlog_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(ServerSocketFactory); | |
66 }; | |
67 | |
38 } // namespace net | 68 } // namespace net |
39 | 69 |
40 #endif // NET_SOCKET_SERVER_SOCKET_H_ | 70 #endif // NET_SOCKET_SERVER_SOCKET_H_ |
OLD | NEW |