[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef NET_SOCKET_SERVER_SOCKET_H_ | ||||
6 | #define NET_SOCKET_SERVER_SOCKET_H_ | ||||
7 | |||||
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 8 | #include <stdint.h> |
9 | |||||
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 11 | #include <string> |
12 | |||||
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 14 | #include "net/base/completion_callback.h" |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 15 | #include "net/base/net_export.h" |
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 16 | |
17 | namespace net { | ||||
18 | |||||
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 19 | class IPEndPoint; |
[email protected] | 3268023f | 2011-05-05 00:08:10 | [diff] [blame] | 20 | class StreamSocket; |
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 21 | |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 22 | class NET_EXPORT ServerSocket { |
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 23 | public: |
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 24 | ServerSocket(); |
25 | virtual ~ServerSocket(); | ||||
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 26 | |
byungchul | 38c3ae7 | 2014-08-25 23:27:46 | [diff] [blame] | 27 | // Binds the socket and starts listening. Destroys the socket to stop |
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 28 | // listening. |
[email protected] | fa6ce92 | 2014-07-17 04:27:04 | [diff] [blame] | 29 | virtual int Listen(const IPEndPoint& address, int backlog) = 0; |
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 30 | |
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 31 | // Binds the socket with address and port, and starts listening. It expects |
32 | // a valid IPv4 or IPv6 address. Otherwise, it returns ERR_ADDRESS_INVALID. | ||||
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 33 | virtual int ListenWithAddressAndPort(const std::string& address_string, |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 34 | uint16_t port, |
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 35 | int backlog); |
36 | |||||
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 37 | // Gets current address the socket is bound to. |
38 | virtual int GetLocalAddress(IPEndPoint* address) const = 0; | ||||
39 | |||||
[email protected] | 2ef2b0e | 2014-07-09 21:12:34 | [diff] [blame] | 40 | // Accepts connection. Callback is called when new connection is |
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 41 | // accepted. |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 42 | virtual int Accept(std::unique_ptr<StreamSocket>* socket, |
[email protected] | df7a30d | 2011-12-03 04:16:50 | [diff] [blame] | 43 | const CompletionCallback& callback) = 0; |
[email protected] | 3871252 | 2011-04-18 23:03:32 | [diff] [blame] | 44 | |
45 | private: | ||||
46 | DISALLOW_COPY_AND_ASSIGN(ServerSocket); | ||||
47 | }; | ||||
48 | |||||
49 | } // namespace net | ||||
50 | |||||
[email protected] | e57a716 | 2011-06-15 04:14:23 | [diff] [blame] | 51 | #endif // NET_SOCKET_SERVER_SOCKET_H_ |