[email protected] | 398dca8 | 2012-04-25 17:54:53 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 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_UDP_SOCKET_LIBEVENT_H_ |
| 6 | #define NET_UDP_UDP_SOCKET_LIBEVENT_H_ |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 7 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 8 | #include "base/memory/ref_counted.h" |
| 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | 7f86564d | 2013-07-18 00:41:22 | [diff] [blame] | 10 | #include "base/message_loop/message_loop.h" |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 11 | #include "base/threading/non_thread_safe.h" |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 12 | #include "net/base/address_family.h" |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 13 | #include "net/base/completion_callback.h" |
[email protected] | 5370c01 | 2011-06-29 03:47:04 | [diff] [blame] | 14 | #include "net/base/io_buffer.h" |
[email protected] | 43d4a026 | 2011-03-09 19:26:04 | [diff] [blame] | 15 | #include "net/base/ip_endpoint.h" |
[email protected] | 7f86564d | 2013-07-18 00:41:22 | [diff] [blame] | 16 | #include "net/base/net_export.h" |
[email protected] | 7f86564d | 2013-07-18 00:41:22 | [diff] [blame] | 17 | #include "net/base/rand_callback.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame^] | 18 | #include "net/log/net_log.h" |
[email protected] | bbfef1f | 2013-08-28 03:00:51 | [diff] [blame] | 19 | #include "net/socket/socket_descriptor.h" |
[email protected] | 5370c01 | 2011-06-29 03:47:04 | [diff] [blame] | 20 | #include "net/udp/datagram_socket.h" |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 21 | |
| 22 | namespace net { |
| 23 | |
[email protected] | 398dca8 | 2012-04-25 17:54:53 | [diff] [blame] | 24 | class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe { |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 25 | public: |
[email protected] | 5370c01 | 2011-06-29 03:47:04 | [diff] [blame] | 26 | UDPSocketLibevent(DatagramSocket::BindType bind_type, |
| 27 | const RandIntCallback& rand_int_cb, |
| 28 | net::NetLog* net_log, |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 29 | const net::NetLog::Source& source); |
| 30 | virtual ~UDPSocketLibevent(); |
| 31 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 32 | // Opens the socket. |
| 33 | // Returns a net error code. |
| 34 | int Open(AddressFamily address_family); |
| 35 | |
| 36 | // Connects the socket to connect with a certain |address|. |
| 37 | // Should be called after Open(). |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 38 | // Returns a net error code. |
[email protected] | 43d4a026 | 2011-03-09 19:26:04 | [diff] [blame] | 39 | int Connect(const IPEndPoint& address); |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 40 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 41 | // Binds the address/port for this socket to |address|. This is generally |
| 42 | // only used on a server. Should be called after Open(). |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 43 | // Returns a net error code. |
[email protected] | 43d4a026 | 2011-03-09 19:26:04 | [diff] [blame] | 44 | int Bind(const IPEndPoint& address); |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 45 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 46 | // Closes the socket. |
| 47 | // TODO(rvargas, hidehiko): Disallow re-Open() after Close(). |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 48 | void Close(); |
| 49 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 50 | // Copies the remote udp address into |address| and returns a net error code. |
[email protected] | 43d4a026 | 2011-03-09 19:26:04 | [diff] [blame] | 51 | int GetPeerAddress(IPEndPoint* address) const; |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 52 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 53 | // Copies the local udp address into |address| and returns a net error code. |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 54 | // (similar to getsockname) |
[email protected] | 43d4a026 | 2011-03-09 19:26:04 | [diff] [blame] | 55 | int GetLocalAddress(IPEndPoint* address) const; |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 56 | |
| 57 | // IO: |
| 58 | // Multiple outstanding read requests are not supported. |
| 59 | // Full duplex mode (reading and writing at the same time) is supported |
| 60 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 61 | // Reads from the socket. |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 62 | // Only usable from the client-side of a UDP socket, after the socket |
| 63 | // has been connected. |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 64 | int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 65 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 66 | // Writes to the socket. |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 67 | // Only usable from the client-side of a UDP socket, after the socket |
| 68 | // has been connected. |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 69 | int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback); |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 70 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 71 | // Reads from a socket and receive sender address information. |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 72 | // |buf| is the buffer to read data into. |
| 73 | // |buf_len| is the maximum amount of data to read. |
| 74 | // |address| is a buffer provided by the caller for receiving the sender |
| 75 | // address information about the received data. This buffer must be kept |
| 76 | // alive by the caller until the callback is placed. |
| 77 | // |address_length| is a ptr to the length of the |address| buffer. This |
| 78 | // is an input parameter containing the maximum size |address| can hold |
| 79 | // and also an output parameter for the size of |address| upon completion. |
[email protected] | 73c5b69 | 2014-07-01 12:43:41 | [diff] [blame] | 80 | // |callback| is the callback on completion of the RecvFrom. |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 81 | // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. |
| 82 | // If ERR_IO_PENDING is returned, the caller must keep |buf|, |address|, |
| 83 | // and |address_length| alive until the callback is called. |
| 84 | int RecvFrom(IOBuffer* buf, |
| 85 | int buf_len, |
[email protected] | 43d4a026 | 2011-03-09 19:26:04 | [diff] [blame] | 86 | IPEndPoint* address, |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 87 | const CompletionCallback& callback); |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 88 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 89 | // Sends to a socket with a particular destination. |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 90 | // |buf| is the buffer to send |
| 91 | // |buf_len| is the number of bytes to send |
| 92 | // |address| is the recipient address. |
| 93 | // |address_length| is the size of the recipient address |
| 94 | // |callback| is the user callback function to call on complete. |
| 95 | // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. |
| 96 | // If ERR_IO_PENDING is returned, the caller must keep |buf| and |address| |
| 97 | // alive until the callback is called. |
| 98 | int SendTo(IOBuffer* buf, |
| 99 | int buf_len, |
[email protected] | 43d4a026 | 2011-03-09 19:26:04 | [diff] [blame] | 100 | const IPEndPoint& address, |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 101 | const CompletionCallback& callback); |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 102 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 103 | // Sets the receive buffer size (in bytes) for the socket. |
| 104 | // Returns a net error code. |
[email protected] | 28b96d1c | 2014-04-09 12:21:15 | [diff] [blame] | 105 | int SetReceiveBufferSize(int32 size); |
[email protected] | df31da4 | 2011-10-18 01:44:40 | [diff] [blame] | 106 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 107 | // Sets the send buffer size (in bytes) for the socket. |
| 108 | // Returns a net error code. |
[email protected] | 28b96d1c | 2014-04-09 12:21:15 | [diff] [blame] | 109 | int SetSendBufferSize(int32 size); |
[email protected] | df31da4 | 2011-10-18 01:44:40 | [diff] [blame] | 110 | |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 111 | // Returns true if the socket is already connected or bound. |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 112 | bool is_connected() const { return is_connected_; } |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 113 | |
[email protected] | eaf10dc | 2011-07-18 21:47:35 | [diff] [blame] | 114 | const BoundNetLog& NetLog() const { return net_log_; } |
| 115 | |
[email protected] | a1781d7b | 2012-07-16 11:52:34 | [diff] [blame] | 116 | // Sets corresponding flags in |socket_options_| to allow the socket |
[email protected] | 7be809df | 2012-08-07 17:00:48 | [diff] [blame] | 117 | // to share the local address to which the socket will be bound with |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 118 | // other processes. Should be called between Open() and Bind(). |
| 119 | // Returns a net error code. |
| 120 | int AllowAddressReuse(); |
[email protected] | a1781d7b | 2012-07-16 11:52:34 | [diff] [blame] | 121 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 122 | // Sets corresponding flags in |socket_options_| to allow or disallow sending |
| 123 | // and receiving packets to and from broadcast addresses. |
| 124 | // Returns a net error code. |
| 125 | int SetBroadcast(bool broadcast); |
[email protected] | a1781d7b | 2012-07-16 11:52:34 | [diff] [blame] | 126 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 127 | // Joins the multicast group. |
[email protected] | 5f01ce2 | 2013-04-30 00:53:18 | [diff] [blame] | 128 | // |group_address| is the group address to join, could be either |
| 129 | // an IPv4 or IPv6 address. |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 130 | // Returns a net error code. |
[email protected] | 5f01ce2 | 2013-04-30 00:53:18 | [diff] [blame] | 131 | int JoinGroup(const IPAddressNumber& group_address) const; |
| 132 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 133 | // Leaves the multicast group. |
[email protected] | 5f01ce2 | 2013-04-30 00:53:18 | [diff] [blame] | 134 | // |group_address| is the group address to leave, could be either |
| 135 | // an IPv4 or IPv6 address. If the socket hasn't joined the group, |
| 136 | // it will be ignored. |
| 137 | // It's optional to leave the multicast group before destroying |
| 138 | // the socket. It will be done by the OS. |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 139 | // Returns a net error code. |
[email protected] | 5f01ce2 | 2013-04-30 00:53:18 | [diff] [blame] | 140 | int LeaveGroup(const IPAddressNumber& group_address) const; |
| 141 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 142 | // Sets interface to use for multicast. If |interface_index| set to 0, |
| 143 | // default interface is used. |
[email protected] | 7b29dac | 2013-12-05 11:19:42 | [diff] [blame] | 144 | // Should be called before Bind(). |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 145 | // Returns a net error code. |
[email protected] | 7b29dac | 2013-12-05 11:19:42 | [diff] [blame] | 146 | int SetMulticastInterface(uint32 interface_index); |
| 147 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 148 | // Sets the time-to-live option for UDP packets sent to the multicast |
[email protected] | 5f01ce2 | 2013-04-30 00:53:18 | [diff] [blame] | 149 | // group address. The default value of this option is 1. |
| 150 | // Cannot be negative or more than 255. |
| 151 | // Should be called before Bind(). |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 152 | // Returns a net error code. |
[email protected] | 5f01ce2 | 2013-04-30 00:53:18 | [diff] [blame] | 153 | int SetMulticastTimeToLive(int time_to_live); |
| 154 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 155 | // Sets the loopback flag for UDP socket. If this flag is true, the host |
[email protected] | 5f01ce2 | 2013-04-30 00:53:18 | [diff] [blame] | 156 | // will receive packets sent to the joined group from itself. |
| 157 | // The default value of this option is true. |
| 158 | // Should be called before Bind(). |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 159 | // Returns a net error code. |
[email protected] | 5f01ce2 | 2013-04-30 00:53:18 | [diff] [blame] | 160 | // |
| 161 | // Note: the behavior of |SetMulticastLoopbackMode| is slightly |
| 162 | // different between Windows and Unix-like systems. The inconsistency only |
| 163 | // happens when there are more than one applications on the same host |
| 164 | // joined to the same multicast group while having different settings on |
| 165 | // multicast loopback mode. On Windows, the applications with loopback off |
| 166 | // will not RECEIVE the loopback packets; while on Unix-like systems, the |
| 167 | // applications with loopback off will not SEND the loopback packets to |
| 168 | // other applications on the same host. See MSDN: http://goo.gl/6vqbj |
| 169 | int SetMulticastLoopbackMode(bool loopback); |
| 170 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 171 | // Sets the differentiated services flags on outgoing packets. May not |
[email protected] | a8a442b3 | 2013-10-22 00:34:41 | [diff] [blame] | 172 | // do anything on some platforms. |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 173 | // Returns a net error code. |
[email protected] | a8a442b3 | 2013-10-22 00:34:41 | [diff] [blame] | 174 | int SetDiffServCodePoint(DiffServCodePoint dscp); |
| 175 | |
[email protected] | 1901dbcb | 2014-03-10 07:18:37 | [diff] [blame] | 176 | // Resets the thread to be used for thread-safety checks. |
| 177 | void DetachFromThread(); |
| 178 | |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 179 | private: |
[email protected] | a1781d7b | 2012-07-16 11:52:34 | [diff] [blame] | 180 | enum SocketOptions { |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 181 | SOCKET_OPTION_MULTICAST_LOOP = 1 << 0 |
[email protected] | a1781d7b | 2012-07-16 11:52:34 | [diff] [blame] | 182 | }; |
| 183 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 184 | class ReadWatcher : public base::MessageLoopForIO::Watcher { |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 185 | public: |
| 186 | explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {} |
| 187 | |
| 188 | // MessageLoopForIO::Watcher methods |
| 189 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 190 | void OnFileCanReadWithoutBlocking(int /* fd */) override; |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 191 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 192 | void OnFileCanWriteWithoutBlocking(int /* fd */) override {} |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 193 | |
| 194 | private: |
| 195 | UDPSocketLibevent* const socket_; |
| 196 | |
| 197 | DISALLOW_COPY_AND_ASSIGN(ReadWatcher); |
| 198 | }; |
| 199 | |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 200 | class WriteWatcher : public base::MessageLoopForIO::Watcher { |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 201 | public: |
| 202 | explicit WriteWatcher(UDPSocketLibevent* socket) : socket_(socket) {} |
| 203 | |
| 204 | // MessageLoopForIO::Watcher methods |
| 205 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 206 | void OnFileCanReadWithoutBlocking(int /* fd */) override {} |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 207 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 208 | void OnFileCanWriteWithoutBlocking(int /* fd */) override; |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 209 | |
| 210 | private: |
| 211 | UDPSocketLibevent* const socket_; |
| 212 | |
| 213 | DISALLOW_COPY_AND_ASSIGN(WriteWatcher); |
| 214 | }; |
| 215 | |
| 216 | void DoReadCallback(int rv); |
| 217 | void DoWriteCallback(int rv); |
| 218 | void DidCompleteRead(); |
| 219 | void DidCompleteWrite(); |
| 220 | |
[email protected] | 8866f62 | 2011-10-18 20:08:10 | [diff] [blame] | 221 | // Handles stats and logging. |result| is the number of bytes transferred, on |
| 222 | // success, or the net error code on failure. On success, LogRead takes in a |
| 223 | // sockaddr and its length, which are mandatory, while LogWrite takes in an |
| 224 | // optional IPEndPoint. |
| 225 | void LogRead(int result, const char* bytes, socklen_t addr_len, |
| 226 | const sockaddr* addr) const; |
| 227 | void LogWrite(int result, const char* bytes, const IPEndPoint* address) const; |
| 228 | |
[email protected] | 06043ae | 2011-03-16 00:00:21 | [diff] [blame] | 229 | // Same as SendTo(), except that address is passed by pointer |
| 230 | // instead of by reference. It is called from Write() with |address| |
| 231 | // set to NULL. |
| 232 | int SendToOrWrite(IOBuffer* buf, |
| 233 | int buf_len, |
| 234 | const IPEndPoint* address, |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 235 | const CompletionCallback& callback); |
[email protected] | 06043ae | 2011-03-16 00:00:21 | [diff] [blame] | 236 | |
[email protected] | 8866f62 | 2011-10-18 20:08:10 | [diff] [blame] | 237 | int InternalConnect(const IPEndPoint& address); |
[email protected] | 06043ae | 2011-03-16 00:00:21 | [diff] [blame] | 238 | int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); |
| 239 | int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 240 | |
[email protected] | a1781d7b | 2012-07-16 11:52:34 | [diff] [blame] | 241 | // Applies |socket_options_| to |socket_|. Should be called before |
| 242 | // Bind(). |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 243 | int SetMulticastOptions(); |
[email protected] | 5370c01 | 2011-06-29 03:47:04 | [diff] [blame] | 244 | int DoBind(const IPEndPoint& address); |
[email protected] | acfe8e8 | 2013-12-12 14:12:56 | [diff] [blame] | 245 | // Binds to a random port on |address|. |
| 246 | int RandomBind(const IPAddressNumber& address); |
[email protected] | 5370c01 | 2011-06-29 03:47:04 | [diff] [blame] | 247 | |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 248 | int socket_; |
sergeyu | 30ad5b3 | 2015-03-27 20:31:02 | [diff] [blame] | 249 | |
[email protected] | 5f01ce2 | 2013-04-30 00:53:18 | [diff] [blame] | 250 | int addr_family_; |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 251 | bool is_connected_; |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 252 | |
[email protected] | 7be809df | 2012-08-07 17:00:48 | [diff] [blame] | 253 | // Bitwise-or'd combination of SocketOptions. Specifies the set of |
| 254 | // options that should be applied to |socket_| before Bind(). |
[email protected] | a1781d7b | 2012-07-16 11:52:34 | [diff] [blame] | 255 | int socket_options_; |
| 256 | |
[email protected] | 7b29dac | 2013-12-05 11:19:42 | [diff] [blame] | 257 | // Multicast interface. |
| 258 | uint32 multicast_interface_; |
| 259 | |
hidehiko | 17fac55 | 2014-12-08 06:02:17 | [diff] [blame] | 260 | // Multicast socket options cached for SetMulticastOption. |
[email protected] | 5f01ce2 | 2013-04-30 00:53:18 | [diff] [blame] | 261 | // Cannot be used after Bind(). |
| 262 | int multicast_time_to_live_; |
| 263 | |
[email protected] | 5370c01 | 2011-06-29 03:47:04 | [diff] [blame] | 264 | // How to do source port binding, used only when UDPSocket is part of |
| 265 | // UDPClientSocket, since UDPServerSocket provides Bind. |
| 266 | DatagramSocket::BindType bind_type_; |
| 267 | |
| 268 | // PRNG function for generating port numbers. |
| 269 | RandIntCallback rand_int_cb_; |
| 270 | |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 271 | // These are mutable since they're just cached copies to make |
| 272 | // GetPeerAddress/GetLocalAddress smarter. |
[email protected] | 43d4a026 | 2011-03-09 19:26:04 | [diff] [blame] | 273 | mutable scoped_ptr<IPEndPoint> local_address_; |
| 274 | mutable scoped_ptr<IPEndPoint> remote_address_; |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 275 | |
| 276 | // The socket's libevent wrappers |
[email protected] | 2da659e | 2013-05-23 20:51:34 | [diff] [blame] | 277 | base::MessageLoopForIO::FileDescriptorWatcher read_socket_watcher_; |
| 278 | base::MessageLoopForIO::FileDescriptorWatcher write_socket_watcher_; |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 279 | |
| 280 | // The corresponding watchers for reads and writes. |
| 281 | ReadWatcher read_watcher_; |
| 282 | WriteWatcher write_watcher_; |
| 283 | |
[email protected] | 43d4a026 | 2011-03-09 19:26:04 | [diff] [blame] | 284 | // The buffer used by InternalRead() to retry Read requests |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 285 | scoped_refptr<IOBuffer> read_buf_; |
| 286 | int read_buf_len_; |
[email protected] | 43d4a026 | 2011-03-09 19:26:04 | [diff] [blame] | 287 | IPEndPoint* recv_from_address_; |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 288 | |
[email protected] | 43d4a026 | 2011-03-09 19:26:04 | [diff] [blame] | 289 | // The buffer used by InternalWrite() to retry Write requests |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 290 | scoped_refptr<IOBuffer> write_buf_; |
| 291 | int write_buf_len_; |
[email protected] | 43d4a026 | 2011-03-09 19:26:04 | [diff] [blame] | 292 | scoped_ptr<IPEndPoint> send_to_address_; |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 293 | |
| 294 | // External callback; called when read is complete. |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 295 | CompletionCallback read_callback_; |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 296 | |
| 297 | // External callback; called when write is complete. |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 298 | CompletionCallback write_callback_; |
[email protected] | a2798d9 | 2011-03-02 22:56:18 | [diff] [blame] | 299 | |
| 300 | BoundNetLog net_log_; |
| 301 | |
| 302 | DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); |
| 303 | }; |
| 304 | |
| 305 | } // namespace net |
| 306 | |
| 307 | #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ |