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

Side by Side Diff: net/udp/udp_socket_win.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_WIN_H_ 5 #ifndef NET_UDP_UDP_SOCKET_WIN_H_
6 #define NET_UDP_UDP_SOCKET_WIN_H_ 6 #define NET_UDP_UDP_SOCKET_WIN_H_
7 7
8 #include <qos2.h> 8 #include <qos2.h>
9 #include <winsock2.h> 9 #include <winsock2.h>
10 10
(...skipping 12 matching lines...) Expand all
23 namespace net { 23 namespace net {
24 24
25 class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe) { 25 class NET_EXPORT UDPSocketWin : NON_EXPORTED_BASE(public base::NonThreadSafe) {
26 public: 26 public:
27 UDPSocketWin(DatagramSocket::BindType bind_type, 27 UDPSocketWin(DatagramSocket::BindType bind_type,
28 const RandIntCallback& rand_int_cb, 28 const RandIntCallback& rand_int_cb,
29 net::NetLog* net_log, 29 net::NetLog* net_log,
30 const net::NetLog::Source& source); 30 const net::NetLog::Source& source);
31 virtual ~UDPSocketWin(); 31 virtual ~UDPSocketWin();
32 32
33 // Opens the socket.
34 // Returns a net error code.
35 int Open(AddressFamily address_family);
rvargas (doing something else) 2014/12/02 23:28:10 #include "net/base/address_family.h"
hidehiko 2014/12/03 17:33:28 Done.
36
33 // Connect the socket to connect with a certain |address|. 37 // Connect the socket to connect with a certain |address|.
34 // Returns a net error code. 38 // Returns a net error code.
35 int Connect(const IPEndPoint& address); 39 int Connect(const IPEndPoint& address);
36 40
37 // Bind the address/port for this socket to |address|. This is generally 41 // Bind the address/port for this socket to |address|. This is generally
38 // only used on a server. 42 // only used on a server.
39 // Returns a net error code. 43 // Returns a net error code.
40 int Bind(const IPEndPoint& address); 44 int Bind(const IPEndPoint& address);
41 45
42 // Close the socket. 46 // Close the socket.
rvargas (doing something else) 2014/12/02 23:28:10 I'd like to document that this object cannot be Op
hidehiko 2014/12/03 17:33:28 +1, but, unfortunately, I found that extensions/br
rvargas (doing something else) 2014/12/03 21:00:16 The current version is still broken for that use c
hidehiko 2014/12/04 04:03:36 OK, let's discuss it separately, considering it is
43 void Close(); 47 void Close();
44 48
45 // Copy the remote udp address into |address| and return a network error code. 49 // Copy the remote udp address into |address| and return a network error code.
46 int GetPeerAddress(IPEndPoint* address) const; 50 int GetPeerAddress(IPEndPoint* address) const;
47 51
48 // Copy the local udp address into |address| and return a network error code. 52 // Copy the local udp address into |address| and return a network error code.
49 // (similar to getsockname) 53 // (similar to getsockname)
50 int GetLocalAddress(IPEndPoint* address) const; 54 int GetLocalAddress(IPEndPoint* address) const;
51 55
52 // IO: 56 // IO:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 101
98 // Set the receive buffer size (in bytes) for the socket. 102 // Set the receive buffer size (in bytes) for the socket.
99 // Returns a net error code. 103 // Returns a net error code.
100 int SetReceiveBufferSize(int32 size); 104 int SetReceiveBufferSize(int32 size);
101 105
102 // Set the send buffer size (in bytes) for the socket. 106 // Set the send buffer size (in bytes) for the socket.
103 // Returns a net error code. 107 // Returns a net error code.
104 int SetSendBufferSize(int32 size); 108 int SetSendBufferSize(int32 size);
105 109
106 // Returns true if the socket is already connected or bound. 110 // Returns true if the socket is already connected or bound.
107 bool is_connected() const { return socket_ != INVALID_SOCKET; } 111 bool is_connected() const { return is_connected_; }
108 112
109 const BoundNetLog& NetLog() const { return net_log_; } 113 const BoundNetLog& NetLog() const { return net_log_; }
110 114
111 // Sets corresponding flags in |socket_options_| to allow the socket 115 // Sets corresponding flags in |socket_options_| to allow the socket
112 // to share the local address to which the socket will be bound with 116 // to share the local address to which the socket will be bound with
113 // other processes. Should be called before Bind(). 117 // other processes. Should be called before Bind().
114 void AllowAddressReuse(); 118 void AllowAddressReuse();
115 119
116 // Sets corresponding flags in |socket_options_| to allow sending 120 // Sets corresponding flags in |socket_options_| to allow sending
117 // and receiving packets to and from broadcast addresses. Should be 121 // and receiving packets to and from broadcast addresses.
118 // called before Bind(). 122 int SetBroadcast(bool broadcast);
119 void AllowBroadcast();
120 123
121 // Join the multicast group. 124 // Join the multicast group.
122 // |group_address| is the group address to join, could be either 125 // |group_address| is the group address to join, could be either
123 // an IPv4 or IPv6 address. 126 // an IPv4 or IPv6 address.
124 // Return a network error code. 127 // Return a network error code.
125 int JoinGroup(const IPAddressNumber& group_address) const; 128 int JoinGroup(const IPAddressNumber& group_address) const;
126 129
127 // Leave the multicast group. 130 // Leave the multicast group.
128 // |group_address| is the group address to leave, could be either 131 // |group_address| is the group address to leave, could be either
129 // 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // Set the differentiated services flags on outgoing packets. May not 166 // Set the differentiated services flags on outgoing packets. May not
164 // do anything on some platforms. 167 // do anything on some platforms.
165 int SetDiffServCodePoint(DiffServCodePoint dscp); 168 int SetDiffServCodePoint(DiffServCodePoint dscp);
166 169
167 // Resets the thread to be used for thread-safety checks. 170 // Resets the thread to be used for thread-safety checks.
168 void DetachFromThread(); 171 void DetachFromThread();
169 172
170 private: 173 private:
171 enum SocketOptions { 174 enum SocketOptions {
172 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0, 175 SOCKET_OPTION_REUSE_ADDRESS = 1 << 0,
173 SOCKET_OPTION_BROADCAST = 1 << 1, 176 SOCKET_OPTION_MULTICAST_LOOP = 1 << 1
174 SOCKET_OPTION_MULTICAST_LOOP = 1 << 2
175 }; 177 };
176 178
177 class Core; 179 class Core;
178 180
179 void DoReadCallback(int rv); 181 void DoReadCallback(int rv);
180 void DoWriteCallback(int rv); 182 void DoWriteCallback(int rv);
181 void DidCompleteRead(); 183 void DidCompleteRead();
182 void DidCompleteWrite(); 184 void DidCompleteWrite();
183 185
184 // Handles stats and logging. |result| is the number of bytes transferred, on 186 // Handles stats and logging. |result| is the number of bytes transferred, on
185 // success, or the net error code on failure. LogRead retrieves the address 187 // success, or the net error code on failure. LogRead retrieves the address
186 // from |recv_addr_storage_|, while LogWrite takes it as an optional argument. 188 // from |recv_addr_storage_|, while LogWrite takes it as an optional argument.
187 void LogRead(int result, const char* bytes) const; 189 void LogRead(int result, const char* bytes) const;
188 void LogWrite(int result, const char* bytes, const IPEndPoint* address) const; 190 void LogWrite(int result, const char* bytes, const IPEndPoint* address) const;
189 191
190 // Returns the OS error code (or 0 on success). 192 // Returns a net error code.
191 int CreateSocket(int addr_family); 193 int CreateSocket(int addr_family);
192 194
193 // Same as SendTo(), except that address is passed by pointer 195 // Same as SendTo(), except that address is passed by pointer
194 // instead of by reference. It is called from Write() with |address| 196 // instead of by reference. It is called from Write() with |address|
195 // set to NULL. 197 // set to NULL.
196 int SendToOrWrite(IOBuffer* buf, 198 int SendToOrWrite(IOBuffer* buf,
197 int buf_len, 199 int buf_len,
198 const IPEndPoint* address, 200 const IPEndPoint* address,
199 const CompletionCallback& callback); 201 const CompletionCallback& callback);
200 202
201 int InternalConnect(const IPEndPoint& address); 203 int InternalConnect(const IPEndPoint& address);
202 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); 204 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address);
203 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); 205 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address);
204 206
205 // Applies |socket_options_| to |socket_|. Should be called before 207 // Applies |socket_options_| to |socket_|. Should be called before
206 // Bind(). 208 // Bind().
207 int SetSocketOptions(); 209 int SetSocketOptions();
208 int DoBind(const IPEndPoint& address); 210 int DoBind(const IPEndPoint& address);
209 // Binds to a random port on |address|. 211 // Binds to a random port on |address|.
210 int RandomBind(const IPAddressNumber& address); 212 int RandomBind(const IPAddressNumber& address);
211 213
212 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| 214 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_|
213 // to an IPEndPoint and writes it to |address|. Returns true on success. 215 // to an IPEndPoint and writes it to |address|. Returns true on success.
214 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const; 216 bool ReceiveAddressToIPEndpoint(IPEndPoint* address) const;
215 217
216 SOCKET socket_; 218 SOCKET socket_;
217 int addr_family_; 219 int addr_family_;
220 bool is_connected_;
218 221
219 // Bitwise-or'd combination of SocketOptions. Specifies the set of 222 // Bitwise-or'd combination of SocketOptions. Specifies the set of
220 // options that should be applied to |socket_| before Bind(). 223 // options that should be applied to |socket_| before Bind().
221 int socket_options_; 224 int socket_options_;
222 225
223 // Multicast interface. 226 // Multicast interface.
224 uint32 multicast_interface_; 227 uint32 multicast_interface_;
225 228
226 // Multicast socket options cached for SetSocketOption. 229 // Multicast socket options cached for SetSocketOption.
227 // Cannot be used after Bind(). 230 // Cannot be used after Bind().
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 SetFlowFn set_flow_func_; 321 SetFlowFn set_flow_func_;
319 322
320 FRIEND_TEST_ALL_PREFIXES(UDPSocketTest, SetDSCPFake); 323 FRIEND_TEST_ALL_PREFIXES(UDPSocketTest, SetDSCPFake);
321 DISALLOW_COPY_AND_ASSIGN(QwaveAPI); 324 DISALLOW_COPY_AND_ASSIGN(QwaveAPI);
322 }; 325 };
323 326
324 327
325 } // namespace net 328 } // namespace net
326 329
327 #endif // NET_UDP_UDP_SOCKET_WIN_H_ 330 #endif // NET_UDP_UDP_SOCKET_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698