OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef BIN_EVENTHANDLER_WIN_H_ | 5 #ifndef BIN_EVENTHANDLER_WIN_H_ |
6 #define BIN_EVENTHANDLER_WIN_H_ | 6 #define BIN_EVENTHANDLER_WIN_H_ |
7 | 7 |
8 #if !defined(BIN_EVENTHANDLER_H_) | 8 #if !defined(BIN_EVENTHANDLER_H_) |
9 #error Do not include eventhandler_win.h directly; use eventhandler.h instead. | 9 #error Do not include eventhandler_win.h directly; use eventhandler.h instead. |
10 #endif | 10 #endif |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 OVERLAPPED* GetCleanOverlapped() { | 86 OVERLAPPED* GetCleanOverlapped() { |
87 memset(&overlapped_, 0, sizeof(overlapped_)); | 87 memset(&overlapped_, 0, sizeof(overlapped_)); |
88 return &overlapped_; | 88 return &overlapped_; |
89 } | 89 } |
90 | 90 |
91 // Returns a WASBUF structure initialized with the data in this IO buffer. | 91 // Returns a WASBUF structure initialized with the data in this IO buffer. |
92 WSABUF* GetWASBUF() { | 92 WSABUF* GetWASBUF() { |
93 wbuf_.buf = GetBufferStart(); | 93 wbuf_.buf = GetBufferStart(); |
94 wbuf_.len = GetBufferSize(); | 94 wbuf_.len = GetBufferSize(); |
95 return &wbuf_; | 95 return &wbuf_; |
96 }; | 96 } |
97 | 97 |
98 void set_data_length(int data_length) { data_length_ = data_length; } | 98 void set_data_length(int data_length) { data_length_ = data_length; } |
99 | 99 |
100 private: | 100 private: |
101 OverlappedBuffer(int buffer_size, Operation operation) | 101 OverlappedBuffer(int buffer_size, Operation operation) |
102 : operation_(operation), buflen_(buffer_size) { | 102 : operation_(operation), buflen_(buffer_size) { |
103 memset(GetBufferStart(), 0, GetBufferSize()); | 103 memset(GetBufferStart(), 0, GetBufferSize()); |
104 if (operation == kRecvFrom) { | 104 if (operation == kRecvFrom) { |
105 // Reserve part of the buffer for the length of source sockaddr | 105 // Reserve part of the buffer for the length of source sockaddr |
106 // and source sockaddr. | 106 // and source sockaddr. |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 events_(events), | 342 events_(events), |
343 recursive_(recursive) { | 343 recursive_(recursive) { |
344 type_ = kDirectoryWatch; | 344 type_ = kDirectoryWatch; |
345 } | 345 } |
346 | 346 |
347 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); | 347 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); |
348 virtual bool IsClosed(); | 348 virtual bool IsClosed(); |
349 | 349 |
350 virtual bool IssueRead(); | 350 virtual bool IssueRead(); |
351 | 351 |
| 352 void Stop(); |
| 353 |
352 private: | 354 private: |
353 int events_; | 355 int events_; |
354 bool recursive_; | 356 bool recursive_; |
355 }; | 357 }; |
356 | 358 |
357 | 359 |
358 class SocketHandle : public Handle { | 360 class SocketHandle : public Handle { |
359 public: | 361 public: |
360 SOCKET socket() { return reinterpret_cast<SOCKET>(handle_); } | 362 SOCKET socket() { return reinterpret_cast<SOCKET>(handle_); } |
361 | 363 |
(...skipping 13 matching lines...) Expand all Loading... |
375 AcceptEx_(NULL), | 377 AcceptEx_(NULL), |
376 pending_accept_count_(0), | 378 pending_accept_count_(0), |
377 accepted_head_(NULL), | 379 accepted_head_(NULL), |
378 accepted_tail_(NULL) { | 380 accepted_tail_(NULL) { |
379 type_ = kListenSocket; | 381 type_ = kListenSocket; |
380 } | 382 } |
381 virtual ~ListenSocket() { | 383 virtual ~ListenSocket() { |
382 ASSERT(!HasPendingAccept()); | 384 ASSERT(!HasPendingAccept()); |
383 ASSERT(accepted_head_ == NULL); | 385 ASSERT(accepted_head_ == NULL); |
384 ASSERT(accepted_tail_ == NULL); | 386 ASSERT(accepted_tail_ == NULL); |
385 }; | 387 } |
386 | 388 |
387 // Socket interface exposing normal socket operations. | 389 // Socket interface exposing normal socket operations. |
388 ClientSocket* Accept(); | 390 ClientSocket* Accept(); |
389 bool CanAccept(); | 391 bool CanAccept(); |
390 | 392 |
391 // Internal interface used by the event handler. | 393 // Internal interface used by the event handler. |
392 bool HasPendingAccept() { return pending_accept_count_ > 0; } | 394 bool HasPendingAccept() { return pending_accept_count_ > 0; } |
393 bool IssueAccept(); | 395 bool IssueAccept(); |
394 void AcceptComplete(OverlappedBuffer* buffer, HANDLE completion_port); | 396 void AcceptComplete(OverlappedBuffer* buffer, HANDLE completion_port); |
395 | 397 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 LoadDisconnectEx(); | 434 LoadDisconnectEx(); |
433 type_ = kClientSocket; | 435 type_ = kClientSocket; |
434 } | 436 } |
435 | 437 |
436 virtual ~ClientSocket() { | 438 virtual ~ClientSocket() { |
437 // Don't delete this object until all pending requests have been handled. | 439 // Don't delete this object until all pending requests have been handled. |
438 ASSERT(!HasPendingRead()); | 440 ASSERT(!HasPendingRead()); |
439 ASSERT(!HasPendingWrite()); | 441 ASSERT(!HasPendingWrite()); |
440 ASSERT(next_ == NULL); | 442 ASSERT(next_ == NULL); |
441 ASSERT(closed_ == true); | 443 ASSERT(closed_ == true); |
442 }; | 444 } |
443 | 445 |
444 void Shutdown(int how); | 446 void Shutdown(int how); |
445 | 447 |
446 // Internal interface used by the event handler. | 448 // Internal interface used by the event handler. |
447 virtual bool IssueRead(); | 449 virtual bool IssueRead(); |
448 virtual bool IssueWrite(); | 450 virtual bool IssueWrite(); |
449 void IssueDisconnect(); | 451 void IssueDisconnect(); |
450 void DisconnectComplete(OverlappedBuffer* buffer); | 452 void DisconnectComplete(OverlappedBuffer* buffer); |
451 | 453 |
452 void ConnectComplete(OverlappedBuffer* buffer); | 454 void ConnectComplete(OverlappedBuffer* buffer); |
(...skipping 24 matching lines...) Expand all Loading... |
477 class DatagramSocket : public SocketHandle { | 479 class DatagramSocket : public SocketHandle { |
478 public: | 480 public: |
479 explicit DatagramSocket(SOCKET s) : SocketHandle(s) { | 481 explicit DatagramSocket(SOCKET s) : SocketHandle(s) { |
480 type_ = kDatagramSocket; | 482 type_ = kDatagramSocket; |
481 } | 483 } |
482 | 484 |
483 virtual ~DatagramSocket() { | 485 virtual ~DatagramSocket() { |
484 // Don't delete this object until all pending requests have been handled. | 486 // Don't delete this object until all pending requests have been handled. |
485 ASSERT(!HasPendingRead()); | 487 ASSERT(!HasPendingRead()); |
486 ASSERT(!HasPendingWrite()); | 488 ASSERT(!HasPendingWrite()); |
487 }; | 489 } |
488 | 490 |
489 // Internal interface used by the event handler. | 491 // Internal interface used by the event handler. |
490 virtual bool IssueRecvFrom(); | 492 virtual bool IssueRecvFrom(); |
491 virtual bool IssueSendTo(sockaddr* sa, socklen_t sa_len); | 493 virtual bool IssueSendTo(sockaddr* sa, socklen_t sa_len); |
492 | 494 |
493 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); | 495 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); |
494 virtual void DoClose(); | 496 virtual void DoClose(); |
495 virtual bool IsClosed(); | 497 virtual bool IsClosed(); |
496 }; | 498 }; |
497 | 499 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 | 531 |
530 TimeoutQueue timeout_queue_; // Time for next timeout. | 532 TimeoutQueue timeout_queue_; // Time for next timeout. |
531 bool shutdown_; | 533 bool shutdown_; |
532 HANDLE completion_port_; | 534 HANDLE completion_port_; |
533 }; | 535 }; |
534 | 536 |
535 } // namespace bin | 537 } // namespace bin |
536 } // namespace dart | 538 } // namespace dart |
537 | 539 |
538 #endif // BIN_EVENTHANDLER_WIN_H_ | 540 #endif // BIN_EVENTHANDLER_WIN_H_ |
OLD | NEW |