OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 | |
5 #ifndef NET_UDP_DATAGRAM_SERVER_SOCKET_H_ | |
6 #define NET_UDP_DATAGRAM_SERVER_SOCKET_H_ | |
7 | |
8 #include "net/base/completion_callback.h" | |
9 #include "net/base/net_util.h" | |
10 #include "net/udp/datagram_socket.h" | |
11 | |
12 namespace net { | |
13 | |
14 class IPEndPoint; | |
15 class IOBuffer; | |
16 | |
17 // A UDP Socket. | |
18 class NET_EXPORT DatagramServerSocket : public DatagramSocket { | |
19 public: | |
20 ~DatagramServerSocket() override {} | |
21 | |
22 // Initialize this socket as a server socket listening at |address|. | |
23 // Returns a network error code. | |
24 virtual int Listen(const IPEndPoint& address) = 0; | |
25 | |
26 // Read from a socket and receive sender address information. | |
27 // |buf| is the buffer to read data into. | |
28 // |buf_len| is the maximum amount of data to read. | |
29 // |address| is a buffer provided by the caller for receiving the sender | |
30 // address information about the received data. This buffer must be kept | |
31 // alive by the caller until the callback is placed. | |
32 // |address_length| is a ptr to the length of the |address| buffer. This | |
33 // is an input parameter containing the maximum size |address| can hold | |
34 // and also an output parameter for the size of |address| upon completion. | |
35 // |callback| is the callback on completion of the RecvFrom. | |
36 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. | |
37 // If ERR_IO_PENDING is returned, the caller must keep |buf|, |address|, | |
38 // and |address_length| alive until the callback is called. | |
39 virtual int RecvFrom(IOBuffer* buf, | |
40 int buf_len, | |
41 IPEndPoint* address, | |
42 const CompletionCallback& callback) = 0; | |
43 | |
44 // Send to a socket with a particular destination. | |
45 // |buf| is the buffer to send | |
46 // |buf_len| is the number of bytes to send | |
47 // |address| is the recipient address. | |
48 // |address_length| is the size of the recipient address | |
49 // |callback| is the user callback function to call on complete. | |
50 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. | |
51 // If ERR_IO_PENDING is returned, the caller must keep |buf| and |address| | |
52 // alive until the callback is called. | |
53 virtual int SendTo(IOBuffer* buf, | |
54 int buf_len, | |
55 const IPEndPoint& address, | |
56 const CompletionCallback& callback) = 0; | |
57 | |
58 // Set the receive buffer size (in bytes) for the socket. | |
59 // Returns a net error code. | |
60 virtual int SetReceiveBufferSize(int32 size) = 0; | |
61 | |
62 // Set the send buffer size (in bytes) for the socket. | |
63 // Returns a net error code. | |
64 virtual int SetSendBufferSize(int32 size) = 0; | |
65 | |
66 // Allow the socket to share the local address to which the socket will | |
67 // be bound with other processes. Should be called before Listen(). | |
68 virtual void AllowAddressReuse() = 0; | |
69 | |
70 // Allow sending and receiving packets to and from broadcast addresses. | |
71 // Should be called before Listen(). | |
72 virtual void AllowBroadcast() = 0; | |
73 | |
74 // Join the multicast group with address |group_address|. | |
75 // Returns a network error code. | |
76 virtual int JoinGroup(const IPAddressNumber& group_address) const = 0; | |
77 | |
78 // Leave the multicast group with address |group_address|. | |
79 // If the socket hasn't joined the group, it will be ignored. | |
80 // It's optional to leave the multicast group before destroying | |
81 // the socket. It will be done by the OS. | |
82 // Returns a network error code. | |
83 virtual int LeaveGroup(const IPAddressNumber& group_address) const = 0; | |
84 | |
85 // Set interface to use for multicast. If |interface_index| set to 0, default | |
86 // interface is used. | |
87 // Should be called before Bind(). | |
88 // Returns a network error code. | |
89 virtual int SetMulticastInterface(uint32 interface_index) = 0; | |
90 | |
91 // Set the time-to-live option for UDP packets sent to the multicast | |
92 // group address. The default value of this option is 1. | |
93 // Cannot be negative or more than 255. | |
94 // Should be called before Bind(). | |
95 // Returns a network error code. | |
96 virtual int SetMulticastTimeToLive(int time_to_live) = 0; | |
97 | |
98 // Set the loopback flag for UDP socket. If this flag is true, the host | |
99 // will receive packets sent to the joined group from itself. | |
100 // The default value of this option is true. | |
101 // Should be called before Bind(). | |
102 // Returns a network error code. | |
103 virtual int SetMulticastLoopbackMode(bool loopback) = 0; | |
104 | |
105 // Set the Differentiated Services Code Point. May do nothing on | |
106 // some platforms. Returns a network error code. | |
107 virtual int SetDiffServCodePoint(DiffServCodePoint dscp) = 0; | |
108 | |
109 // Resets the thread to be used for thread-safety checks. | |
110 virtual void DetachFromThread() = 0; | |
111 }; | |
112 | |
113 } // namespace net | |
114 | |
115 #endif // NET_UDP_DATAGRAM_SERVER_SOCKET_H_ | |
OLD | NEW |