| OLD | NEW |
| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // other applications on the same host. See MSDN: http://goo.gl/6vqbj | 167 // other applications on the same host. See MSDN: http://goo.gl/6vqbj |
| 168 int SetMulticastLoopbackMode(bool loopback); | 168 int SetMulticastLoopbackMode(bool loopback); |
| 169 | 169 |
| 170 // Sets the differentiated services flags on outgoing packets. May not | 170 // Sets the differentiated services flags on outgoing packets. May not |
| 171 // do anything on some platforms. | 171 // do anything on some platforms. |
| 172 int SetDiffServCodePoint(DiffServCodePoint dscp); | 172 int SetDiffServCodePoint(DiffServCodePoint dscp); |
| 173 | 173 |
| 174 // Resets the thread to be used for thread-safety checks. | 174 // Resets the thread to be used for thread-safety checks. |
| 175 void DetachFromThread(); | 175 void DetachFromThread(); |
| 176 | 176 |
| 177 // This class by default uses overlapped IO. Call this method before Open() |
| 178 // to switch to non-blocking IO. |
| 179 void UseNonBlockingIO(); |
| 180 |
| 177 private: | 181 private: |
| 178 enum SocketOptions { | 182 enum SocketOptions { |
| 179 SOCKET_OPTION_MULTICAST_LOOP = 1 << 0 | 183 SOCKET_OPTION_MULTICAST_LOOP = 1 << 0 |
| 180 }; | 184 }; |
| 181 | 185 |
| 182 class Core; | 186 class Core; |
| 183 | 187 |
| 184 void DoReadCallback(int rv); | 188 void DoReadCallback(int rv); |
| 185 void DoWriteCallback(int rv); | 189 void DoWriteCallback(int rv); |
| 186 void DidCompleteRead(); | 190 |
| 187 void DidCompleteWrite(); | 191 // Version for using overlapped IO. |
| 192 void DidCompleteReadOverlapped(); |
| 193 void DidCompleteWriteOverlapped(); |
| 194 |
| 195 // Version for using non-blocking IO. |
| 196 void OnReadSignaledNonBlocking(); |
| 197 void OnWriteSignaledNonBlocking(); |
| 188 | 198 |
| 189 // Handles stats and logging. |result| is the number of bytes transferred, on | 199 // Handles stats and logging. |result| is the number of bytes transferred, on |
| 190 // success, or the net error code on failure. LogRead retrieves the address | 200 // success, or the net error code on failure. LogRead retrieves the address |
| 191 // from |recv_addr_storage_|, while LogWrite takes it as an optional argument. | 201 // from |recv_addr_storage_|, while LogWrite takes it as an optional argument. |
| 192 void LogRead(int result, const char* bytes) const; | 202 void LogRead(int result, const char* bytes) const; |
| 193 void LogWrite(int result, const char* bytes, const IPEndPoint* address) const; | 203 void LogWrite(int result, const char* bytes, const IPEndPoint* address) const; |
| 194 | 204 |
| 195 // Same as SendTo(), except that address is passed by pointer | 205 // Same as SendTo(), except that address is passed by pointer |
| 196 // instead of by reference. It is called from Write() with |address| | 206 // instead of by reference. It is called from Write() with |address| |
| 197 // set to NULL. | 207 // set to NULL. |
| 198 int SendToOrWrite(IOBuffer* buf, | 208 int SendToOrWrite(IOBuffer* buf, |
| 199 int buf_len, | 209 int buf_len, |
| 200 const IPEndPoint* address, | 210 const IPEndPoint* address, |
| 201 const CompletionCallback& callback); | 211 const CompletionCallback& callback); |
| 202 | 212 |
| 203 int InternalConnect(const IPEndPoint& address); | 213 int InternalConnect(const IPEndPoint& address); |
| 204 int InternalRecvFrom(IOBuffer* buf, int buf_len, IPEndPoint* address); | 214 |
| 205 int InternalSendTo(IOBuffer* buf, int buf_len, const IPEndPoint* address); | 215 // Version for using overlapped IO. |
| 216 int InternalRecvFromOverlapped(IOBuffer* buf, |
| 217 int buf_len, |
| 218 IPEndPoint* address); |
| 219 int InternalSendToOverlapped(IOBuffer* buf, |
| 220 int buf_len, |
| 221 const IPEndPoint* address); |
| 222 |
| 223 // Version for using non-blocking IO. |
| 224 int InternalRecvFromNonBlocking(IOBuffer* buf, |
| 225 int buf_len, |
| 226 IPEndPoint* address); |
| 227 int InternalSendToNonBlocking(IOBuffer* buf, |
| 228 int buf_len, |
| 229 const IPEndPoint* address); |
| 206 | 230 |
| 207 // Applies |socket_options_| to |socket_|. Should be called before | 231 // Applies |socket_options_| to |socket_|. Should be called before |
| 208 // Bind(). | 232 // Bind(). |
| 209 int SetMulticastOptions(); | 233 int SetMulticastOptions(); |
| 210 int DoBind(const IPEndPoint& address); | 234 int DoBind(const IPEndPoint& address); |
| 211 // Binds to a random port on |address|. | 235 // Binds to a random port on |address|. |
| 212 int RandomBind(const IPAddressNumber& address); | 236 int RandomBind(const IPAddressNumber& address); |
| 213 | 237 |
| 214 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| | 238 // Attempts to convert the data in |recv_addr_storage_| and |recv_addr_len_| |
| 215 // to an IPEndPoint and writes it to |address|. Returns true on success. | 239 // to an IPEndPoint and writes it to |address|. Returns true on success. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 240 // These are mutable since they're just cached copies to make | 264 // These are mutable since they're just cached copies to make |
| 241 // GetPeerAddress/GetLocalAddress smarter. | 265 // GetPeerAddress/GetLocalAddress smarter. |
| 242 mutable scoped_ptr<IPEndPoint> local_address_; | 266 mutable scoped_ptr<IPEndPoint> local_address_; |
| 243 mutable scoped_ptr<IPEndPoint> remote_address_; | 267 mutable scoped_ptr<IPEndPoint> remote_address_; |
| 244 | 268 |
| 245 // The core of the socket that can live longer than the socket itself. We pass | 269 // The core of the socket that can live longer than the socket itself. We pass |
| 246 // resources to the Windows async IO functions and we have to make sure that | 270 // resources to the Windows async IO functions and we have to make sure that |
| 247 // they are not destroyed while the OS still references them. | 271 // they are not destroyed while the OS still references them. |
| 248 scoped_refptr<Core> core_; | 272 scoped_refptr<Core> core_; |
| 249 | 273 |
| 274 bool non_blocking_reads_initialized_; |
| 275 bool non_blocking_writes_initialized_; |
| 276 |
| 250 IPEndPoint* recv_from_address_; | 277 IPEndPoint* recv_from_address_; |
| 251 | 278 |
| 252 // Cached copy of the current address we're sending to, if any. Used for | 279 // Cached copy of the current address we're sending to, if any. Used for |
| 253 // logging. | 280 // logging. |
| 254 scoped_ptr<IPEndPoint> send_to_address_; | 281 scoped_ptr<IPEndPoint> send_to_address_; |
| 255 | 282 |
| 256 // External callback; called when read is complete. | 283 // External callback; called when read is complete. |
| 257 CompletionCallback read_callback_; | 284 CompletionCallback read_callback_; |
| 258 | 285 |
| 259 // External callback; called when write is complete. | 286 // External callback; called when write is complete. |
| 260 CompletionCallback write_callback_; | 287 CompletionCallback write_callback_; |
| 261 | 288 |
| 262 BoundNetLog net_log_; | 289 BoundNetLog net_log_; |
| 263 | 290 |
| 264 // QWAVE data. Used to set DSCP bits on outgoing packets. | 291 // QWAVE data. Used to set DSCP bits on outgoing packets. |
| 265 HANDLE qos_handle_; | 292 HANDLE qos_handle_; |
| 266 QOS_FLOWID qos_flow_id_; | 293 QOS_FLOWID qos_flow_id_; |
| 267 | 294 |
| 295 // True if overlapp IO is used. |
| 296 bool use_overlapped_io_; |
| 297 |
| 268 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); | 298 DISALLOW_COPY_AND_ASSIGN(UDPSocketWin); |
| 269 }; | 299 }; |
| 270 | 300 |
| 271 //----------------------------------------------------------------------------- | 301 //----------------------------------------------------------------------------- |
| 272 | 302 |
| 273 // QWAVE (Quality Windows Audio/Video Experience) is the latest windows | 303 // QWAVE (Quality Windows Audio/Video Experience) is the latest windows |
| 274 // library for setting packet priorities (and other things). Unfortunately, | 304 // library for setting packet priorities (and other things). Unfortunately, |
| 275 // Microsoft has decided that setting the DSCP bits with setsockopt() no | 305 // Microsoft has decided that setting the DSCP bits with setsockopt() no |
| 276 // longer works, so we have to use this API instead. | 306 // longer works, so we have to use this API instead. |
| 277 // This class is meant to be used as a singleton. It exposes a few dynamically | 307 // This class is meant to be used as a singleton. It exposes a few dynamically |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 SetFlowFn set_flow_func_; | 351 SetFlowFn set_flow_func_; |
| 322 | 352 |
| 323 FRIEND_TEST_ALL_PREFIXES(UDPSocketTest, SetDSCPFake); | 353 FRIEND_TEST_ALL_PREFIXES(UDPSocketTest, SetDSCPFake); |
| 324 DISALLOW_COPY_AND_ASSIGN(QwaveAPI); | 354 DISALLOW_COPY_AND_ASSIGN(QwaveAPI); |
| 325 }; | 355 }; |
| 326 | 356 |
| 327 | 357 |
| 328 } // namespace net | 358 } // namespace net |
| 329 | 359 |
| 330 #endif // NET_UDP_UDP_SOCKET_WIN_H_ | 360 #endif // NET_UDP_UDP_SOCKET_WIN_H_ |
| OLD | NEW |