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