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