1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/socket/server_socket.h"
6
7 #include "net/base/ip_address.h"
8 #include "net/base/ip_endpoint.h"
9 #include "net/base/net_errors.h"
10
11 namespace net {
12
13 ServerSocket::ServerSocket() = default;
14
15 ServerSocket::~ServerSocket() = default;
16
ListenWithAddressAndPort(const std::string & address_string,uint16_t port,int backlog)17 int ServerSocket::ListenWithAddressAndPort(const std::string& address_string,
18 uint16_t port,
19 int backlog) {
20 IPAddress ip_address;
21 if (!ip_address.AssignFromIPLiteral(address_string)) {
22 return ERR_ADDRESS_INVALID;
23 }
24
25 return Listen(IPEndPoint(ip_address, port), backlog,
26 /*ipv6_only=*/std::nullopt);
27 }
28
Accept(std::unique_ptr<StreamSocket> * socket,net::CompletionOnceCallback callback,net::IPEndPoint * peer_address)29 int ServerSocket::Accept(std::unique_ptr<StreamSocket>* socket,
30 net::CompletionOnceCallback callback,
31 net::IPEndPoint* peer_address) {
32 if (peer_address) {
33 *peer_address = IPEndPoint();
34 }
35 return Accept(socket, std::move(callback));
36 }
37
38 } // namespace net
39