server_socket.cc 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2014 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. #include "net/socket/server_socket.h"
  5. #include "net/base/ip_address.h"
  6. #include "net/base/ip_endpoint.h"
  7. #include "net/base/net_errors.h"
  8. namespace net {
  9. ServerSocket::ServerSocket() = default;
  10. ServerSocket::~ServerSocket() = default;
  11. int ServerSocket::ListenWithAddressAndPort(const std::string& address_string,
  12. uint16_t port,
  13. int backlog) {
  14. IPAddress ip_address;
  15. if (!ip_address.AssignFromIPLiteral(address_string)) {
  16. return ERR_ADDRESS_INVALID;
  17. }
  18. return Listen(IPEndPoint(ip_address, port), backlog);
  19. }
  20. int ServerSocket::Accept(std::unique_ptr<StreamSocket>* socket,
  21. net::CompletionOnceCallback callback,
  22. net::IPEndPoint* peer_address) {
  23. if (peer_address) {
  24. *peer_address = IPEndPoint();
  25. }
  26. return Accept(socket, std::move(callback));
  27. }
  28. } // namespace net