Add a function to create a bookmark app from a WebApplicationInfo.
[chromium-blink-merge.git] / net / udp / datagram_server_socket.h
bloba7191d12c02ffc1e36641c5a086bdc202c108a92
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.
5 #ifndef NET_UDP_DATAGRAM_SERVER_SOCKET_H_
6 #define NET_UDP_DATAGRAM_SERVER_SOCKET_H_
8 #include "net/base/completion_callback.h"
9 #include "net/base/net_util.h"
10 #include "net/udp/datagram_socket.h"
12 namespace net {
14 class IPEndPoint;
15 class IOBuffer;
17 // A UDP Socket.
18 class NET_EXPORT DatagramServerSocket : public DatagramSocket {
19 public:
20 virtual ~DatagramServerSocket() {}
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;
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| the callback on completion of the Recv.
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;
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;
58 // Set the receive buffer size (in bytes) for the socket.
59 virtual bool SetReceiveBufferSize(int32 size) = 0;
61 // Set the send buffer size (in bytes) for the socket.
62 virtual bool SetSendBufferSize(int32 size) = 0;
64 // Allow the socket to share the local address to which the socket will
65 // be bound with other processes. Should be called before Listen().
66 virtual void AllowAddressReuse() = 0;
68 // Allow sending and receiving packets to and from broadcast addresses.
69 // Should be called before Listen().
70 virtual void AllowBroadcast() = 0;
72 // Join the multicast group with address |group_address|.
73 // Returns a network error code.
74 virtual int JoinGroup(const IPAddressNumber& group_address) const = 0;
76 // Leave the multicast group with address |group_address|.
77 // If the socket hasn't joined the group, it will be ignored.
78 // It's optional to leave the multicast group before destroying
79 // the socket. It will be done by the OS.
80 // Returns a network error code.
81 virtual int LeaveGroup(const IPAddressNumber& group_address) const = 0;
83 // Set interface to use for multicast. If |interface_index| set to 0, default
84 // interface is used.
85 // Should be called before Bind().
86 // Returns a network error code.
87 virtual int SetMulticastInterface(uint32 interface_index) = 0;
89 // Set the time-to-live option for UDP packets sent to the multicast
90 // group address. The default value of this option is 1.
91 // Cannot be negative or more than 255.
92 // Should be called before Bind().
93 // Returns a network error code.
94 virtual int SetMulticastTimeToLive(int time_to_live) = 0;
96 // Set the loopback flag for UDP socket. If this flag is true, the host
97 // will receive packets sent to the joined group from itself.
98 // The default value of this option is true.
99 // Should be called before Bind().
100 // Returns a network error code.
101 virtual int SetMulticastLoopbackMode(bool loopback) = 0;
103 // Set the Differentiated Services Code Point. May do nothing on
104 // some platforms. Returns a network error code.
105 virtual int SetDiffServCodePoint(DiffServCodePoint dscp) = 0;
107 // Resets the thread to be used for thread-safety checks.
108 virtual void DetachFromThread() = 0;
111 } // namespace net
113 #endif // NET_UDP_DATAGRAM_SERVER_SOCKET_H_