blob: 9ad5cf81b936df21cbaff24714a5a8c0f1b54585 [file] [log] [blame]
[email protected]38712522011-04-18 23:03:321// 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 Drissman13fc8932015-12-20 04:40:468#include <stdint.h>
9
danakj655b66c2016-04-16 00:51:3810#include <memory>
[email protected]2ef2b0e2014-07-09 21:12:3411#include <string>
12
Avi Drissman13fc8932015-12-20 04:40:4613#include "base/macros.h"
[email protected]38712522011-04-18 23:03:3214#include "net/base/completion_callback.h"
[email protected]172da1b2011-08-12 15:52:2615#include "net/base/net_export.h"
[email protected]38712522011-04-18 23:03:3216
17namespace net {
18
[email protected]38712522011-04-18 23:03:3219class IPEndPoint;
[email protected]3268023f2011-05-05 00:08:1020class StreamSocket;
[email protected]38712522011-04-18 23:03:3221
[email protected]172da1b2011-08-12 15:52:2622class NET_EXPORT ServerSocket {
[email protected]38712522011-04-18 23:03:3223 public:
[email protected]2ef2b0e2014-07-09 21:12:3424 ServerSocket();
25 virtual ~ServerSocket();
[email protected]38712522011-04-18 23:03:3226
byungchul38c3ae72014-08-25 23:27:4627 // Binds the socket and starts listening. Destroys the socket to stop
[email protected]38712522011-04-18 23:03:3228 // listening.
[email protected]fa6ce922014-07-17 04:27:0429 virtual int Listen(const IPEndPoint& address, int backlog) = 0;
[email protected]38712522011-04-18 23:03:3230
[email protected]2ef2b0e2014-07-09 21:12:3431 // 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]2ef2b0e2014-07-09 21:12:3433 virtual int ListenWithAddressAndPort(const std::string& address_string,
Avi Drissman13fc8932015-12-20 04:40:4634 uint16_t port,
[email protected]2ef2b0e2014-07-09 21:12:3435 int backlog);
36
[email protected]38712522011-04-18 23:03:3237 // Gets current address the socket is bound to.
38 virtual int GetLocalAddress(IPEndPoint* address) const = 0;
39
[email protected]2ef2b0e2014-07-09 21:12:3440 // Accepts connection. Callback is called when new connection is
[email protected]38712522011-04-18 23:03:3241 // accepted.
danakj655b66c2016-04-16 00:51:3842 virtual int Accept(std::unique_ptr<StreamSocket>* socket,
[email protected]df7a30d2011-12-03 04:16:5043 const CompletionCallback& callback) = 0;
[email protected]38712522011-04-18 23:03:3244
45 private:
46 DISALLOW_COPY_AND_ASSIGN(ServerSocket);
47};
48
49} // namespace net
50
[email protected]e57a7162011-06-15 04:14:2351#endif // NET_SOCKET_SERVER_SOCKET_H_