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