quic_simple_server_socket.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright (c) 2019 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/tools/quic/quic_simple_server_socket.h"
  5. #include "net/base/net_errors.h"
  6. #include "net/log/net_log_source.h"
  7. #include "net/third_party/quiche/src/quiche/quic/core/quic_constants.h"
  8. namespace net {
  9. std::unique_ptr<UDPServerSocket> CreateQuicSimpleServerSocket(
  10. const IPEndPoint& address,
  11. IPEndPoint* server_address) {
  12. auto socket =
  13. std::make_unique<UDPServerSocket>(/*net_log=*/nullptr, NetLogSource());
  14. socket->AllowAddressReuse();
  15. int rc = socket->Listen(address);
  16. if (rc < 0) {
  17. LOG(ERROR) << "Listen() failed: " << ErrorToString(rc);
  18. return nullptr;
  19. }
  20. // These send and receive buffer sizes are sized for a single connection,
  21. // because the default usage of QuicSimpleServer is as a test server with
  22. // one or two clients. Adjust higher for use with many clients.
  23. rc = socket->SetReceiveBufferSize(
  24. static_cast<int32_t>(quic::kDefaultSocketReceiveBuffer));
  25. if (rc < 0) {
  26. LOG(ERROR) << "SetReceiveBufferSize() failed: " << ErrorToString(rc);
  27. return nullptr;
  28. }
  29. rc = socket->SetSendBufferSize(20 * quic::kMaxOutgoingPacketSize);
  30. if (rc < 0) {
  31. LOG(ERROR) << "SetSendBufferSize() failed: " << ErrorToString(rc);
  32. return nullptr;
  33. }
  34. rc = socket->GetLocalAddress(server_address);
  35. if (rc < 0) {
  36. LOG(ERROR) << "GetLocalAddress() failed: " << ErrorToString(rc);
  37. return nullptr;
  38. }
  39. VLOG(1) << "Listening on " << server_address->ToString();
  40. return socket;
  41. }
  42. } // namespace net