1 // Copyright 2012 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 #ifndef NET_SOCKET_UDP_SERVER_SOCKET_H_ 6 #define NET_SOCKET_UDP_SERVER_SOCKET_H_ 7 8 #include <stdint.h> 9 10 #include "net/base/completion_once_callback.h" 11 #include "net/base/net_export.h" 12 #include "net/socket/datagram_server_socket.h" 13 #include "net/socket/udp_socket.h" 14 15 namespace net { 16 17 class IPAddress; 18 class IPEndPoint; 19 class NetLog; 20 struct NetLogSource; 21 22 // A server socket that uses UDP as the transport layer. 23 class NET_EXPORT UDPServerSocket : public DatagramServerSocket { 24 public: 25 UDPServerSocket(net::NetLog* net_log, const net::NetLogSource& source); 26 27 UDPServerSocket(const UDPServerSocket&) = delete; 28 UDPServerSocket& operator=(const UDPServerSocket&) = delete; 29 30 ~UDPServerSocket() override; 31 32 // Implement DatagramServerSocket: 33 int Listen(const IPEndPoint& address) override; 34 int RecvFrom(IOBuffer* buf, 35 int buf_len, 36 IPEndPoint* address, 37 CompletionOnceCallback callback) override; 38 int SendTo(IOBuffer* buf, 39 int buf_len, 40 const IPEndPoint& address, 41 CompletionOnceCallback callback) override; 42 int SetReceiveBufferSize(int32_t size) override; 43 int SetSendBufferSize(int32_t size) override; 44 int SetDoNotFragment() override; 45 int SetRecvTos() override; 46 void SetMsgConfirm(bool confirm) override; 47 void Close() override; 48 int GetPeerAddress(IPEndPoint* address) const override; 49 int GetLocalAddress(IPEndPoint* address) const override; 50 void UseNonBlockingIO() override; 51 const NetLogWithSource& NetLog() const override; 52 void AllowAddressReuse() override; 53 void AllowBroadcast() override; 54 void AllowAddressSharingForMulticast() override; 55 int JoinGroup(const IPAddress& group_address) const override; 56 int LeaveGroup(const IPAddress& group_address) const override; 57 int SetMulticastInterface(uint32_t interface_index) override; 58 int SetMulticastTimeToLive(int time_to_live) override; 59 int SetMulticastLoopbackMode(bool loopback) override; 60 int SetDiffServCodePoint(DiffServCodePoint dscp) override; 61 int SetTos(DiffServCodePoint dscp, EcnCodePoint ecn) override; 62 void DetachFromThread() override; 63 DscpAndEcn GetLastTos() const override; 64 65 private: 66 UDPSocket socket_; 67 bool allow_address_reuse_ = false; 68 bool allow_broadcast_ = false; 69 bool allow_address_sharing_for_multicast_ = false; 70 }; 71 72 } // namespace net 73 74 #endif // NET_SOCKET_UDP_SERVER_SOCKET_H_ 75