Index: dart/runtime/bin/eventhandler_win.h |
diff --git a/dart/runtime/bin/eventhandler_win.h b/dart/runtime/bin/eventhandler_win.h |
index c54ef0726c9efb742e4c8fc3cc2c8a34b95fcf8f..9e256d2e17317628f6b49aba8bc5456d8623f5f4 100644 |
--- a/dart/runtime/bin/eventhandler_win.h |
+++ b/dart/runtime/bin/eventhandler_win.h |
@@ -29,13 +29,6 @@ class ClientSocket; |
class ListenSocket; |
-struct InterruptMessage { |
- intptr_t id; |
- Dart_Port dart_port; |
- int64_t data; |
-}; |
- |
- |
// An OverlappedBuffer encapsulates the OVERLAPPED structure and the |
// associated data buffer. For accept it also contains the pre-created |
// socket for the client. |
@@ -161,7 +154,7 @@ class OverlappedBuffer { |
// Abstract super class for holding information on listen and connected |
// sockets. |
-class Handle { |
+class Handle : public DescriptorInfoBase { |
public: |
enum Type { |
kFile, |
@@ -225,7 +218,6 @@ class Handle { |
EventHandlerImplementation* event_handler) = 0; |
HANDLE handle() { return handle_; } |
- Dart_Port port() { return port_; } |
void Lock(); |
void Unlock(); |
@@ -238,10 +230,6 @@ class Handle { |
bool IsHandleClosed() const { return handle_ == INVALID_HANDLE_VALUE; } |
- void SetPortAndMask(Dart_Port port, intptr_t mask) { |
- port_ = port; |
- mask_ = mask; |
- } |
Type type() { return type_; } |
bool is_file() { return type_ == kFile; } |
bool is_socket() { return type_ == kListenSocket || |
@@ -250,8 +238,6 @@ class Handle { |
bool is_listen_socket() { return type_ == kListenSocket; } |
bool is_client_socket() { return type_ == kClientSocket; } |
bool is_datagram_socket() { return type_ == kDatagramSocket; } |
- void set_mask(intptr_t mask) { mask_ = mask; } |
- intptr_t mask() { return mask_; } |
void MarkDoesNotSupportOverlappedIO() { |
flags_ |= (1 << kDoesNotSupportOverlappedIO); |
@@ -274,15 +260,12 @@ class Handle { |
kError = 4 |
}; |
- explicit Handle(HANDLE handle); |
- Handle(HANDLE handle, Dart_Port port); |
+ explicit Handle(intptr_t handle); |
virtual void HandleIssueError(); |
Type type_; |
HANDLE handle_; |
- Dart_Port port_; // Dart port to communicate events for this socket. |
- intptr_t mask_; // Mask of events to report through the port. |
HANDLE completion_port_; |
EventHandlerImplementation* event_handler_; |
@@ -298,12 +281,12 @@ class Handle { |
}; |
-class FileHandle : public Handle { |
+class FileHandle : public DescriptorInfoSingleMixin<Handle> { |
public: |
explicit FileHandle(HANDLE handle) |
- : Handle(handle) { type_ = kFile; } |
- FileHandle(HANDLE handle, Dart_Port port) |
- : Handle(handle, port) { type_ = kFile; } |
+ : DescriptorInfoSingleMixin(reinterpret_cast<intptr_t>(handle)) { |
+ type_ = kFile; |
+ } |
virtual void EnsureInitialized(EventHandlerImplementation* event_handler); |
virtual bool IsClosed(); |
@@ -339,10 +322,10 @@ class StdHandle : public FileHandle { |
}; |
-class DirectoryWatchHandle : public Handle { |
+class DirectoryWatchHandle : public DescriptorInfoSingleMixin<Handle> { |
public: |
DirectoryWatchHandle(HANDLE handle, int events, bool recursive) |
- : Handle(handle), |
+ : DescriptorInfoSingleMixin(reinterpret_cast<intptr_t>(handle)), |
events_(events), |
recursive_(recursive) { |
type_ = kDirectoryWatch; |
@@ -366,11 +349,8 @@ class SocketHandle : public Handle { |
SOCKET socket() const { return socket_; } |
protected: |
- explicit SocketHandle(SOCKET s) |
- : Handle(reinterpret_cast<HANDLE>(s)), |
- socket_(s) {} |
- SocketHandle(SOCKET s, Dart_Port port) |
- : Handle(reinterpret_cast<HANDLE>(s), port), |
+ explicit SocketHandle(intptr_t s) |
+ : Handle(s), |
socket_(s) {} |
virtual void HandleIssueError(); |
@@ -381,13 +361,14 @@ class SocketHandle : public Handle { |
// Information on listen sockets. |
-class ListenSocket : public SocketHandle { |
+class ListenSocket : public DescriptorInfoMultipleMixin<SocketHandle> { |
public: |
- explicit ListenSocket(SOCKET s) : SocketHandle(s), |
- AcceptEx_(NULL), |
- pending_accept_count_(0), |
- accepted_head_(NULL), |
- accepted_tail_(NULL) { |
+ explicit ListenSocket(intptr_t s) : DescriptorInfoMultipleMixin(s), |
+ AcceptEx_(NULL), |
+ pending_accept_count_(0), |
+ accepted_head_(NULL), |
+ accepted_tail_(NULL), |
+ accepted_count_(0) { |
type_ = kListenSocket; |
} |
virtual ~ListenSocket() { |
@@ -412,22 +393,32 @@ class ListenSocket : public SocketHandle { |
int pending_accept_count() { return pending_accept_count_; } |
+ int accepted_count() { return accepted_count_; } |
+ |
private: |
bool LoadAcceptEx(); |
LPFN_ACCEPTEX AcceptEx_; |
+ |
+ // The number of asynchronous `IssueAccept` operations which haven't completed |
+ // yet. |
int pending_accept_count_; |
+ |
// Linked list of accepted connections provided by completion code. Ready to |
// be handed over through accept. |
ClientSocket* accepted_head_; |
ClientSocket* accepted_tail_; |
+ |
+ // The number of accepted connections which are waiting to be removed from |
+ // this queue and processed by dart isolates. |
+ int accepted_count_; |
}; |
// Information on connected sockets. |
-class ClientSocket : public SocketHandle { |
+class ClientSocket : public DescriptorInfoSingleMixin<SocketHandle> { |
public: |
- explicit ClientSocket(SOCKET s) : SocketHandle(s), |
+ explicit ClientSocket(intptr_t s) : DescriptorInfoSingleMixin(s), |
DisconnectEx_(NULL), |
next_(NULL), |
connected_(false), |
@@ -436,15 +427,6 @@ class ClientSocket : public SocketHandle { |
type_ = kClientSocket; |
} |
- ClientSocket(SOCKET s, Dart_Port port) : SocketHandle(s, port), |
- DisconnectEx_(NULL), |
- next_(NULL), |
- connected_(false), |
- closed_(false) { |
- LoadDisconnectEx(); |
- type_ = kClientSocket; |
- } |
- |
virtual ~ClientSocket() { |
// Don't delete this object until all pending requests have been handled. |
ASSERT(!HasPendingRead()); |
@@ -486,9 +468,9 @@ class ClientSocket : public SocketHandle { |
}; |
-class DatagramSocket : public SocketHandle { |
+class DatagramSocket : public DescriptorInfoSingleMixin<SocketHandle> { |
public: |
- explicit DatagramSocket(SOCKET s) : SocketHandle(s) { |
+ explicit DatagramSocket(intptr_t s) : DescriptorInfoSingleMixin(s) { |
type_ = kDatagramSocket; |
} |
@@ -523,6 +505,7 @@ class EventHandlerImplementation { |
void HandleInterrupt(InterruptMessage* msg); |
void HandleTimeout(); |
void HandleAccept(ListenSocket* listen_socket, OverlappedBuffer* buffer); |
+ void TryDispatchingPendingAccepts(ListenSocket *listen_socket); |
void HandleRead(Handle* handle, int bytes, OverlappedBuffer* buffer); |
void HandleRecvFrom(Handle* handle, int bytes, OverlappedBuffer* buffer); |
void HandleWrite(Handle* handle, int bytes, OverlappedBuffer* buffer); |