1 // Copyright 2011 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_DATAGRAM_SOCKET_H_ 6 #define NET_SOCKET_DATAGRAM_SOCKET_H_ 7 8 #include "net/base/net_export.h" 9 10 namespace net { 11 12 class IPEndPoint; 13 class NetLogWithSource; 14 15 // A datagram socket is an interface to a protocol which exchanges 16 // datagrams, like UDP. 17 class NET_EXPORT_PRIVATE DatagramSocket { 18 public: 19 // Type of source port binding to use. 20 enum BindType { 21 RANDOM_BIND, 22 DEFAULT_BIND, 23 }; 24 25 virtual ~DatagramSocket() = default; 26 27 // Close the socket. 28 virtual void Close() = 0; 29 30 // Copy the remote udp address into |address| and return a network error code. 31 virtual int GetPeerAddress(IPEndPoint* address) const = 0; 32 33 // Copy the local udp address into |address| and return a network error code. 34 // (similar to getsockname) 35 virtual int GetLocalAddress(IPEndPoint* address) const = 0; 36 37 // Switch to use non-blocking IO. Must be called right after construction and 38 // before other calls. 39 virtual void UseNonBlockingIO() = 0; 40 41 // Requests that packets sent by this socket not be fragment, either locally 42 // by the host, or by routers (via the DF bit in the IPv4 packet header). 43 // May not be supported by all platforms. Returns a network error code if 44 // there was a problem, but the socket will still be usable. Can not 45 // return ERR_IO_PENDING. 46 virtual int SetDoNotFragment() = 0; 47 48 // If |confirm| is true, then the MSG_CONFIRM flag will be passed to 49 // subsequent writes if it's supported by the platform. 50 virtual void SetMsgConfirm(bool confirm) = 0; 51 52 // Gets the NetLog for this socket. 53 virtual const NetLogWithSource& NetLog() const = 0; 54 }; 55 56 } // namespace net 57 58 #endif // NET_SOCKET_DATAGRAM_SOCKET_H_ 59