Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: net/udp/udp_socket_libevent.h

Issue 721273002: Remove timing limitation to set Broadcast, ReceiveBuffer, and SendBuffer options from UDPSocket. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_UDP_UDP_SOCKET_LIBEVENT_H_ 5 #ifndef NET_UDP_UDP_SOCKET_LIBEVENT_H_
6 #define NET_UDP_UDP_SOCKET_LIBEVENT_H_ 6 #define NET_UDP_UDP_SOCKET_LIBEVENT_H_
7 7
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 10 matching lines...) Expand all
21 namespace net { 21 namespace net {
22 22
23 class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe { 23 class NET_EXPORT UDPSocketLibevent : public base::NonThreadSafe {
24 public: 24 public:
25 UDPSocketLibevent(DatagramSocket::BindType bind_type, 25 UDPSocketLibevent(DatagramSocket::BindType bind_type,
26 const RandIntCallback& rand_int_cb, 26 const RandIntCallback& rand_int_cb,
27 net::NetLog* net_log, 27 net::NetLog* net_log,
28 const net::NetLog::Source& source); 28 const net::NetLog::Source& source);
29 virtual ~UDPSocketLibevent(); 29 virtual ~UDPSocketLibevent();
30 30
31 // Opens the socket.
32 // Returns a net error code.
33 int Open(AddressFamily address_family);
34
31 // Connect the socket to connect with a certain |address|. 35 // Connect the socket to connect with a certain |address|.
36 // Should be called after Open().
rvargas (doing something else) 2014/12/02 23:28:09 The comments should be the same for both implement
hidehiko 2014/12/03 17:33:27 Done.
32 // Returns a net error code. 37 // Returns a net error code.
33 int Connect(const IPEndPoint& address); 38 int Connect(const IPEndPoint& address);
34 39
35 // Bind the address/port for this socket to |address|. This is generally 40 // Bind the address/port for this socket to |address|. This is generally
36 // only used on a server. 41 // only used on a server. Should be called after Open().
37 // Returns a net error code. 42 // Returns a net error code.
38 int Bind(const IPEndPoint& address); 43 int Bind(const IPEndPoint& address);
39 44
40 // Close the socket. 45 // Close the socket.
41 void Close(); 46 void Close();
42 47
43 // Copy the remote udp address into |address| and return a network error code. 48 // Copy the remote udp address into |address| and return a network error code.
44 int GetPeerAddress(IPEndPoint* address) const; 49 int GetPeerAddress(IPEndPoint* address) const;
45 50
46 // Copy the local udp address into |address| and return a network error code. 51 // Copy the local udp address into |address| and return a network error code.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // |callback| is the user callback function to call on complete. 92 // |callback| is the user callback function to call on complete.
88 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress. 93 // Returns a net error code, or ERR_IO_PENDING if the IO is in progress.
89 // If ERR_IO_PENDING is returned, the caller must keep |buf| and |address| 94 // If ERR_IO_PENDING is returned, the caller must keep |buf| and |address|
90 // alive until the callback is called. 95 // alive until the callback is called.
91 int SendTo(IOBuffer* buf, 96 int SendTo(IOBuffer* buf,
92 int buf_len, 97 int buf_len,
93 const IPEndPoint& address, 98 const IPEndPoint& address,
94 const CompletionCallback& callback); 99 const CompletionCallback& callback);
95 100
96 // Set the receive buffer size (in bytes) for the socket. 101 // Set the receive buffer size (in bytes) for the socket.
102 // Returns a network error code.
97 int SetReceiveBufferSize(int32 size); 103 int SetReceiveBufferSize(int32 size);
98 104
99 // Set the send buffer size (in bytes) for the socket. 105 // Set the send buffer size (in bytes) for the socket.
106 // Returns a network error code.
100 int SetSendBufferSize(int32 size); 107 int SetSendBufferSize(int32 size);
101 108
102 // Returns true if the socket is already connected or bound. 109 // Returns true if the socket is already connected or bound.
103 bool is_connected() const { return socket_ != kInvalidSocket; } 110 bool is_connected() const { return is_connected_; }
104 111
105 const BoundNetLog& NetLog() const { return net_log_; } 112 const BoundNetLog& NetLog() const { return net_log_; }
106 113
107 // Sets corresponding flags in |socket_options_| to allow the socket 114 // Sets corresponding flags in |socket_options_| to allow the socket
108 // to share the local address to which the socket will be bound with 115 // to share the local address to which the socket will be bound with
109 // other processes. Should be called before Bind(). 116 // other processes. Should be called before Bind().
110 void AllowAddressReuse(); 117 void AllowAddressReuse();
111 118
112 // Sets corresponding flags in |socket_options_| to allow sending 119 // Sets corresponding flags in |socket_options_| to allow or disallow sending
113 // and receiving packets to and from broadcast addresses. Should be 120 // and receiving packets to and from broadcast addresses.
114 // called before Bind(). 121 // Returns a network error code.
115 void AllowBroadcast(); 122 int SetBroadcast(bool broadcast);
116 123
117 // Join the multicast group. 124 // Join the multicast group.
118 // |group_address| is the group address to join, could be either 125 // |group_address| is the group address to join, could be either
119 // an IPv4 or IPv6 address. 126 // an IPv4 or IPv6 address.
120 // Return a network error code. 127 // Return a network error code.
121 int JoinGroup(const IPAddressNumber& group_address) const; 128 int JoinGroup(const IPAddressNumber& group_address) const;
122 129
123 // Leave the multicast group. 130 // Leave the multicast group.
124 // |group_address| is the group address to leave, could be either 131 // |group_address| is the group address to leave, could be either
125 // an IPv4 or IPv6 address. If the socket hasn't joined the group, 132 // an IPv4 or IPv6 address. If the socket hasn't joined the group,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 // do anything on some platforms. 169 // do anything on some platforms.
163 // Return a network error code. 170 // Return a network error code.
164 int SetDiffServCodePoint(DiffServCodePoint dscp); 171 int SetDiffServCodePoint(DiffServCodePoint dscp);
165 172
166 // Resets the thread to be used for thread-safety checks. 173 // Resets the thread to be used for thread-safety checks.
167 void DetachFromThread(); 174 void DetachFromThread();
168 175
169 private: 176 private:
170 enum SocketOptions { 177 enum SocketOptions {
171 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, 178 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0,
172 SOCKET_OPTION_BROADCAST = 1 << 1, 179 SOCKET_OPTION_MULTICAST_LOOP = 1 << 1
173 SOCKET_OPTION_MULTICAST_LOOP = 1 << 2
174 }; 180 };
175 181
176 class ReadWatcher : public base::MessageLoopForIO::Watcher { 182 class ReadWatcher : public base::MessageLoopForIO::Watcher {
177 public: 183 public:
178 explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {} 184 explicit ReadWatcher(UDPSocketLibevent* socket) : socket_(socket) {}
179 185
180 // MessageLoopForIO::Watcher methods 186 // MessageLoopForIO::Watcher methods
181 187
182 void OnFileCanReadWithoutBlocking(int /* fd */) override; 188 void OnFileCanReadWithoutBlocking(int /* fd */) override;
183 189
(...skipping 27 matching lines...) Expand all
211 void DidCompleteWrite(); 217 void DidCompleteWrite();
212 218
213 // Handles stats and logging. |result| is the number of bytes transferred, on 219 // Handles stats and logging. |result| is the number of bytes transferred, on
214 // success, or the net error code on failure. On success, LogRead takes in a 220 // success, or the net error code on failure. On success, LogRead takes in a
215 // sockaddr and its length, which are mandatory, while LogWrite takes in an 221 // sockaddr and its length, which are mandatory, while LogWrite takes in an
216 // optional IPEndPoint. 222 // optional IPEndPoint.
217 void LogRead(int result, const char* bytes, socklen_t addr_len, 223 void LogRead(int result, const char* bytes, socklen_t addr_len,
218 const sockaddr* addr) const; 224 const sockaddr* addr) const;
219 void LogWrite(int result, const char* bytes, const IPEndPoint* address) const; 225 void LogWrite(int result, const char* bytes, const IPEndPoint* address) const;
220 226
221 // Returns the OS error code (or 0 on success). 227 // Returns a network error code.
rvargas (doing something else) 2014/12/02 23:28:09 nit: network -> net
hidehiko 2014/12/03 17:33:27 Done.
222 int CreateSocket(int addr_family); 228 int CreateSocket(int addr_family);
223 229
224 // Same as SendTo(), except that address is passed by pointer 230 // Same as SendTo(), except that address is passed by pointer
225 // instead of by reference. It is called from Write() with |address| 231 // instead of by reference. It is called from Write() with |address|
226 // set to NULL. 232 // set to NULL.
227 int SendToOrWrite(IOBuffer* buf, 233 int SendToOrWrite(IOBuffer* buf,
228 int buf_len, 234 int buf_len,
229 const IPEndPoint* address, 235 const IPEndPoint* address,
230 const CompletionCallback& callback); 236 const CompletionCallback& callback);
231 237
232 int InternalConnect(const IPEndPoint& address); 238 int InternalConnect(const IPEndPoint& address);
233 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); 239 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address);
234 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); 240 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address);
235 241
236 // Applies |socket_options_| to |socket_|. Should be called before 242 // Applies |socket_options_| to |socket_|. Should be called before
237 // Bind(). 243 // Bind().
238 int SetSocketOptions(); 244 int SetSocketOptions();
239 int DoBind(const IPEndPoint& address); 245 int DoBind(const IPEndPoint& address);
240 // Binds to a random port on |address|. 246 // Binds to a random port on |address|.
241 int RandomBind(const IPAddressNumber& address); 247 int RandomBind(const IPAddressNumber& address);
242 248
243 int socket_; 249 int socket_;
244 int addr_family_; 250 int addr_family_;
251 bool is_connected_;
245 252
246 // Bitwise-or'd combination of SocketOptions. Specifies the set of 253 // Bitwise-or'd combination of SocketOptions. Specifies the set of
247 // options that should be applied to |socket_| before Bind(). 254 // options that should be applied to |socket_| before Bind().
248 int socket_options_; 255 int socket_options_;
249 256
250 // Multicast interface. 257 // Multicast interface.
251 uint32 multicast_interface_; 258 uint32 multicast_interface_;
252 259
253 // Multicast socket options cached for SetSocketOption. 260 // Multicast socket options cached for SetSocketOption.
254 // Cannot be used after Bind(). 261 // Cannot be used after Bind().
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 CompletionCallback write_callback_; 298 CompletionCallback write_callback_;
292 299
293 BoundNetLog net_log_; 300 BoundNetLog net_log_;
294 301
295 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent); 302 DISALLOW_COPY_AND_ASSIGN(UDPSocketLibevent);
296 }; 303 };
297 304
298 } // namespace net 305 } // namespace net
299 306
300 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_ 307 #endif // NET_UDP_UDP_SOCKET_LIBEVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698