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 <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "net/base/completion_callback.h" | 12 #include "net/base/completion_callback.h" |
12 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
13 | 14 |
14 namespace net { | 15 namespace net { |
15 | 16 |
16 class IPEndPoint; | 17 class IPEndPoint; |
17 class StreamSocket; | 18 class StreamSocket; |
18 | 19 |
19 class NET_EXPORT ServerSocket { | 20 class NET_EXPORT ServerSocket { |
20 public: | 21 public: |
21 ServerSocket(); | 22 ServerSocket(); |
22 virtual ~ServerSocket(); | 23 virtual ~ServerSocket(); |
23 | 24 |
24 // Binds the socket and starts listening. Destroys the socket to stop | 25 // Binds the socket and starts listening. Destroys the socket to stop |
25 // listening. | 26 // listening. |
26 virtual int Listen(const IPEndPoint& address, int backlog) = 0; | 27 virtual int Listen(const IPEndPoint& address, int backlog) = 0; |
27 | 28 |
28 // Binds the socket with address and port, and starts listening. It expects | 29 // Binds the socket with address and port, and starts listening. It expects |
29 // a valid IPv4 or IPv6 address. Otherwise, it returns ERR_ADDRESS_INVALID. | 30 // a valid IPv4 or IPv6 address. Otherwise, it returns ERR_ADDRESS_INVALID. |
30 // Subclasses may override this function if |address_string| is in a different | 31 // Subclasses may override this function if |address_string| is in a different |
31 // format, for example, unix domain socket path. | 32 // format, for example, unix domain socket path. |
32 virtual int ListenWithAddressAndPort(const std::string& address_string, | 33 virtual int ListenWithAddressAndPort(const std::string& address_string, |
33 int port, | 34 uint16 port, |
34 int backlog); | 35 int backlog); |
35 | 36 |
36 // Gets current address the socket is bound to. | 37 // Gets current address the socket is bound to. |
37 virtual int GetLocalAddress(IPEndPoint* address) const = 0; | 38 virtual int GetLocalAddress(IPEndPoint* address) const = 0; |
38 | 39 |
39 // Accepts connection. Callback is called when new connection is | 40 // Accepts connection. Callback is called when new connection is |
40 // accepted. | 41 // accepted. |
41 virtual int Accept(scoped_ptr<StreamSocket>* socket, | 42 virtual int Accept(scoped_ptr<StreamSocket>* socket, |
42 const CompletionCallback& callback) = 0; | 43 const CompletionCallback& callback) = 0; |
43 | 44 |
44 private: | 45 private: |
45 DISALLOW_COPY_AND_ASSIGN(ServerSocket); | 46 DISALLOW_COPY_AND_ASSIGN(ServerSocket); |
46 }; | 47 }; |
47 | 48 |
48 } // namespace net | 49 } // namespace net |
49 | 50 |
50 #endif // NET_SOCKET_SERVER_SOCKET_H_ | 51 #endif // NET_SOCKET_SERVER_SOCKET_H_ |
OLD | NEW |