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_SOCKET_UDP_SOCKET_WIN_H_ | 5 #ifndef NET_SOCKET_UDP_SOCKET_WIN_H_ |
6 #define NET_SOCKET_UDP_SOCKET_WIN_H_ | 6 #define NET_SOCKET_UDP_SOCKET_WIN_H_ |
7 | 7 |
8 #include <qos2.h> | 8 #include <qos2.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <winsock2.h> | 10 #include <winsock2.h> |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // other applications on the same host. See MSDN: http://goo.gl/6vqbj | 190 // other applications on the same host. See MSDN: http://goo.gl/6vqbj |
191 int SetMulticastLoopbackMode(bool loopback); | 191 int SetMulticastLoopbackMode(bool loopback); |
192 | 192 |
193 // Sets the differentiated services flags on outgoing packets. May not | 193 // Sets the differentiated services flags on outgoing packets. May not |
194 // do anything on some platforms. | 194 // do anything on some platforms. |
195 int SetDiffServCodePoint(DiffServCodePoint dscp); | 195 int SetDiffServCodePoint(DiffServCodePoint dscp); |
196 | 196 |
197 // Resets the thread to be used for thread-safety checks. | 197 // Resets the thread to be used for thread-safety checks. |
198 void DetachFromThread(); | 198 void DetachFromThread(); |
199 | 199 |
200 // This class by default uses overlapped IO. Call this method before Open() | |
201 // to switch to non-blocking IO. | |
202 void UseNonBlockingIO(); | |
203 | |
204 private: | 200 private: |
205 enum SocketOptions { | 201 enum SocketOptions { |
206 SOCKET_OPTION_MULTICAST_LOOP = 1 << 0 | 202 SOCKET_OPTION_MULTICAST_LOOP = 1 << 0 |
207 }; | 203 }; |
208 | 204 |
209 class Core; | |
210 | |
211 void DoReadCallback(int rv); | 205 void DoReadCallback(int rv); |
212 void DoWriteCallback(int rv); | 206 void DoWriteCallback(int rv); |
213 | 207 |
214 void DidCompleteRead(); | |
215 void DidCompleteWrite(); | |
216 | |
217 // base::ObjectWatcher::Delegate implementation. | 208 // base::ObjectWatcher::Delegate implementation. |
218 void OnObjectSignaled(HANDLE object) override; | 209 void OnObjectSignaled(HANDLE object) override; |
219 void OnReadSignaled(); | 210 void OnReadSignaled(); |
220 void OnWriteSignaled(); | 211 void OnWriteSignaled(); |
221 | 212 |
222 void WatchForReadWrite(); | 213 void WatchForReadWrite(); |
223 | 214 |
224 // Handles stats and logging. |result| is the number of bytes transferred, on | 215 // Handles stats and logging. |result| is the number of bytes transferred, on |
225 // success, or the net error code on failure. | 216 // success, or the net error code on failure. |
226 void LogRead(int result, const char* bytes, const IPEndPoint* address) const; | 217 void LogRead(int result, const char* bytes, const IPEndPoint* address) const; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 DatagramSocket::BindType bind_type_; | 270 DatagramSocket::BindType bind_type_; |
280 | 271 |
281 // PRNG function for generating port numbers. | 272 // PRNG function for generating port numbers. |
282 RandIntCallback rand_int_cb_; | 273 RandIntCallback rand_int_cb_; |
283 | 274 |
284 // These are mutable since they're just cached copies to make | 275 // These are mutable since they're just cached copies to make |
285 // GetPeerAddress/GetLocalAddress smarter. | 276 // GetPeerAddress/GetLocalAddress smarter. |
286 mutable std::unique_ptr<IPEndPoint> local_address_; | 277 mutable std::unique_ptr<IPEndPoint> local_address_; |
287 mutable std::unique_ptr<IPEndPoint> remote_address_; | 278 mutable std::unique_ptr<IPEndPoint> remote_address_; |
288 | 279 |
289 // The core of the socket that can live longer than the socket itself. We pass | |
290 // resources to the Windows async IO functions and we have to make sure that | |
291 // they are not destroyed while the OS still references them. | |
292 scoped_refptr<Core> core_; | |
293 | |
294 // True if non-blocking IO is used. | |
295 bool use_non_blocking_io_; | |
296 | |
297 // Watches |read_write_event_|. | 280 // Watches |read_write_event_|. |
298 base::win::ObjectWatcher read_write_watcher_; | 281 base::win::ObjectWatcher read_write_watcher_; |
299 | 282 |
300 // Events for read and write. | 283 // Events for read and write. |
301 base::win::ScopedHandle read_write_event_; | 284 base::win::ScopedHandle read_write_event_; |
302 | 285 |
303 // The buffers used in Read() and Write(). | 286 // The buffers used in Read() and Write(). |
304 scoped_refptr<IOBuffer> read_iobuffer_; | 287 scoped_refptr<IOBuffer> read_iobuffer_; |
305 scoped_refptr<IOBuffer> write_iobuffer_; | 288 scoped_refptr<IOBuffer> write_iobuffer_; |
306 | 289 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 SetFlowFn set_flow_func_; | 364 SetFlowFn set_flow_func_; |
382 | 365 |
383 FRIEND_TEST_ALL_PREFIXES(UDPSocketTest, SetDSCPFake); | 366 FRIEND_TEST_ALL_PREFIXES(UDPSocketTest, SetDSCPFake); |
384 DISALLOW_COPY_AND_ASSIGN(QwaveAPI); | 367 DISALLOW_COPY_AND_ASSIGN(QwaveAPI); |
385 }; | 368 }; |
386 | 369 |
387 | 370 |
388 } // namespace net | 371 } // namespace net |
389 | 372 |
390 #endif // NET_SOCKET_UDP_SOCKET_WIN_H_ | 373 #endif // NET_SOCKET_UDP_SOCKET_WIN_H_ |
OLD | NEW |