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 void SetMsgConfirm(bool confirm) override; 46 void Close() override; 47 int GetPeerAddress(IPEndPoint* address) const override; 48 int GetLocalAddress(IPEndPoint* address) const override; 49 void UseNonBlockingIO() override; 50 const NetLogWithSource& NetLog() const override; 51 void AllowAddressReuse() override; 52 void AllowBroadcast() override; 53 void AllowAddressSharingForMulticast() override; 54 int JoinGroup(const IPAddress& group_address) const override; 55 int LeaveGroup(const IPAddress& group_address) const override; 56 int SetMulticastInterface(uint32_t interface_index) override; 57 int SetMulticastTimeToLive(int time_to_live) override; 58 int SetMulticastLoopbackMode(bool loopback) override; 59 int SetDiffServCodePoint(DiffServCodePoint dscp) override; 60 void DetachFromThread() override; 61 62 private: 63 UDPSocket socket_; 64 bool allow_address_reuse_ = false; 65 bool allow_broadcast_ = false; 66 bool allow_address_sharing_for_multicast_ = false; 67 }; 68 69 } // namespace net 70 71 #endif // NET_SOCKET_UDP_SERVER_SOCKET_H_ 72