| 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 23 matching lines...) Expand all Loading... |
| 34 Dart_Port dart_port; | 34 Dart_Port dart_port; |
| 35 int64_t data; | 35 int64_t data; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 | 38 |
| 39 // An OverlappedBuffer encapsulates the OVERLAPPED structure and the | 39 // An OverlappedBuffer encapsulates the OVERLAPPED structure and the |
| 40 // associated data buffer. For accept it also contains the pre-created | 40 // associated data buffer. For accept it also contains the pre-created |
| 41 // socket for the client. | 41 // socket for the client. |
| 42 class OverlappedBuffer { | 42 class OverlappedBuffer { |
| 43 public: | 43 public: |
| 44 enum Operation { kAccept, kRead, kRecvFrom, kWrite, kSendTo, kDisconnect }; | 44 enum Operation { |
| 45 kAccept, kRead, kRecvFrom, kWrite, kSendTo, kDisconnect, kConnect |
| 46 }; |
| 45 | 47 |
| 46 static OverlappedBuffer* AllocateAcceptBuffer(int buffer_size); | 48 static OverlappedBuffer* AllocateAcceptBuffer(int buffer_size); |
| 47 static OverlappedBuffer* AllocateReadBuffer(int buffer_size); | 49 static OverlappedBuffer* AllocateReadBuffer(int buffer_size); |
| 48 static OverlappedBuffer* AllocateRecvFromBuffer(int buffer_size); | 50 static OverlappedBuffer* AllocateRecvFromBuffer(int buffer_size); |
| 49 static OverlappedBuffer* AllocateWriteBuffer(int buffer_size); | 51 static OverlappedBuffer* AllocateWriteBuffer(int buffer_size); |
| 50 static OverlappedBuffer* AllocateSendToBuffer(int buffer_size); | 52 static OverlappedBuffer* AllocateSendToBuffer(int buffer_size); |
| 51 static OverlappedBuffer* AllocateDisconnectBuffer(); | 53 static OverlappedBuffer* AllocateDisconnectBuffer(); |
| 54 static OverlappedBuffer* AllocateConnectBuffer(); |
| 52 static void DisposeBuffer(OverlappedBuffer* buffer); | 55 static void DisposeBuffer(OverlappedBuffer* buffer); |
| 53 | 56 |
| 54 // Find the IO buffer from the OVERLAPPED address. | 57 // Find the IO buffer from the OVERLAPPED address. |
| 55 static OverlappedBuffer* GetFromOverlapped(OVERLAPPED* overlapped); | 58 static OverlappedBuffer* GetFromOverlapped(OVERLAPPED* overlapped); |
| 56 | 59 |
| 57 // Read data from a buffer which has been received. It will read up | 60 // Read data from a buffer which has been received. It will read up |
| 58 // to num_bytes bytes of data returning the actual number of bytes | 61 // to num_bytes bytes of data returning the actual number of bytes |
| 59 // read. This will update the index of the next byte in the buffer | 62 // read. This will update the index of the next byte in the buffer |
| 60 // so calling Read several times will keep returning new data from | 63 // so calling Read several times will keep returning new data from |
| 61 // the buffer until all data have been read. | 64 // the buffer until all data have been read. |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 ClientSocket* accepted_head_; | 411 ClientSocket* accepted_head_; |
| 409 ClientSocket* accepted_tail_; | 412 ClientSocket* accepted_tail_; |
| 410 }; | 413 }; |
| 411 | 414 |
| 412 | 415 |
| 413 // Information on connected sockets. | 416 // Information on connected sockets. |
| 414 class ClientSocket : public SocketHandle { | 417 class ClientSocket : public SocketHandle { |
| 415 public: | 418 public: |
| 416 explicit ClientSocket(SOCKET s) : SocketHandle(s), | 419 explicit ClientSocket(SOCKET s) : SocketHandle(s), |
| 417 DisconnectEx_(NULL), | 420 DisconnectEx_(NULL), |
| 418 next_(NULL) { | 421 next_(NULL), |
| 422 connected_(false), |
| 423 closed_(false) { |
| 419 LoadDisconnectEx(); | 424 LoadDisconnectEx(); |
| 420 type_ = kClientSocket; | 425 type_ = kClientSocket; |
| 421 } | 426 } |
| 422 | 427 |
| 423 ClientSocket(SOCKET s, Dart_Port port) : SocketHandle(s, port), | 428 ClientSocket(SOCKET s, Dart_Port port) : SocketHandle(s, port), |
| 424 DisconnectEx_(NULL), | 429 DisconnectEx_(NULL), |
| 425 next_(NULL) { | 430 next_(NULL), |
| 431 connected_(false), |
| 432 closed_(false) { |
| 426 LoadDisconnectEx(); | 433 LoadDisconnectEx(); |
| 427 type_ = kClientSocket; | 434 type_ = kClientSocket; |
| 428 } | 435 } |
| 429 | 436 |
| 430 virtual ~ClientSocket() { | 437 virtual ~ClientSocket() { |
| 431 // Don't delete this object until all pending requests have been handled. | 438 // Don't delete this object until all pending requests have been handled. |
| 432 ASSERT(!HasPendingRead()); | 439 ASSERT(!HasPendingRead()); |
| 433 ASSERT(!HasPendingWrite()); | 440 ASSERT(!HasPendingWrite()); |
| 434 ASSERT(next_ == NULL); | 441 ASSERT(next_ == NULL); |
| 435 }; | 442 }; |
| 436 | 443 |
| 437 void Shutdown(int how); | 444 void Shutdown(int how); |
| 438 | 445 |
| 439 // Internal interface used by the event handler. | 446 // Internal interface used by the event handler. |
| 440 virtual bool IssueRead(); | 447 virtual bool IssueRead(); |
| 441 virtual bool IssueWrite(); | 448 virtual bool IssueWrite(); |
| 442 void IssueDisconnect(); | 449 void IssueDisconnect(); |
| 443 void DisconnectComplete(OverlappedBuffer* buffer); | 450 void DisconnectComplete(OverlappedBuffer* buffer); |
| 444 | 451 |
| 452 void ConnectComplete(OverlappedBuffer* buffer); |
| 453 |
| 445 virtual void EnsureInitialized( | 454 virtual void EnsureInitialized( |
| 446 EventHandlerImplementation* event_handler); | 455 EventHandlerImplementation* event_handler); |
| 447 virtual void DoClose(); | 456 virtual void DoClose(); |
| 448 virtual bool IsClosed(); | 457 virtual bool IsClosed(); |
| 449 | 458 |
| 450 ClientSocket* next() { return next_; } | 459 ClientSocket* next() { return next_; } |
| 451 void set_next(ClientSocket* next) { next_ = next; } | 460 void set_next(ClientSocket* next) { next_ = next; } |
| 452 | 461 |
| 462 void mark_connected() { |
| 463 connected_ = true; |
| 464 } |
| 465 bool is_connected() const { return connected_; } |
| 466 |
| 453 private: | 467 private: |
| 454 bool LoadDisconnectEx(); | 468 bool LoadDisconnectEx(); |
| 455 | 469 |
| 456 LPFN_DISCONNECTEX DisconnectEx_; | 470 LPFN_DISCONNECTEX DisconnectEx_; |
| 457 ClientSocket* next_; | 471 ClientSocket* next_; |
| 472 bool connected_; |
| 473 bool closed_; |
| 458 }; | 474 }; |
| 459 | 475 |
| 460 | 476 |
| 461 class DatagramSocket : public SocketHandle { | 477 class DatagramSocket : public SocketHandle { |
| 462 public: | 478 public: |
| 463 explicit DatagramSocket(SOCKET s) : SocketHandle(s) { | 479 explicit DatagramSocket(SOCKET s) : SocketHandle(s) { |
| 464 type_ = kDatagramSocket; | 480 type_ = kDatagramSocket; |
| 465 } | 481 } |
| 466 | 482 |
| 467 virtual ~DatagramSocket() { | 483 virtual ~DatagramSocket() { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 496 void HandleTimeout(); | 512 void HandleTimeout(); |
| 497 void HandleAccept(ListenSocket* listen_socket, OverlappedBuffer* buffer); | 513 void HandleAccept(ListenSocket* listen_socket, OverlappedBuffer* buffer); |
| 498 void HandleClosed(Handle* handle); | 514 void HandleClosed(Handle* handle); |
| 499 void HandleError(Handle* handle); | 515 void HandleError(Handle* handle); |
| 500 void HandleRead(Handle* handle, int bytes, OverlappedBuffer* buffer); | 516 void HandleRead(Handle* handle, int bytes, OverlappedBuffer* buffer); |
| 501 void HandleRecvFrom(Handle* handle, int bytes, OverlappedBuffer* buffer); | 517 void HandleRecvFrom(Handle* handle, int bytes, OverlappedBuffer* buffer); |
| 502 void HandleWrite(Handle* handle, int bytes, OverlappedBuffer* buffer); | 518 void HandleWrite(Handle* handle, int bytes, OverlappedBuffer* buffer); |
| 503 void HandleDisconnect(ClientSocket* client_socket, | 519 void HandleDisconnect(ClientSocket* client_socket, |
| 504 int bytes, | 520 int bytes, |
| 505 OverlappedBuffer* buffer); | 521 OverlappedBuffer* buffer); |
| 522 void HandleConnect(ClientSocket* client_socket, |
| 523 int bytes, |
| 524 OverlappedBuffer* buffer); |
| 506 void HandleIOCompletion(DWORD bytes, ULONG_PTR key, OVERLAPPED* overlapped); | 525 void HandleIOCompletion(DWORD bytes, ULONG_PTR key, OVERLAPPED* overlapped); |
| 507 | 526 |
| 508 HANDLE completion_port() { return completion_port_; } | 527 HANDLE completion_port() { return completion_port_; } |
| 509 | 528 |
| 510 private: | 529 private: |
| 511 ClientSocket* client_sockets_head_; | 530 ClientSocket* client_sockets_head_; |
| 512 | 531 |
| 513 TimeoutQueue timeout_queue_; // Time for next timeout. | 532 TimeoutQueue timeout_queue_; // Time for next timeout. |
| 514 bool shutdown_; | 533 bool shutdown_; |
| 515 HANDLE completion_port_; | 534 HANDLE completion_port_; |
| 516 }; | 535 }; |
| 517 | 536 |
| 518 } // namespace bin | 537 } // namespace bin |
| 519 } // namespace dart | 538 } // namespace dart |
| 520 | 539 |
| 521 #endif // BIN_EVENTHANDLER_WIN_H_ | 540 #endif // BIN_EVENTHANDLER_WIN_H_ |
| OLD | NEW |