Index: dart/runtime/bin/eventhandler_win.h |
diff --git a/dart/runtime/bin/eventhandler_win.h b/dart/runtime/bin/eventhandler_win.h |
index 9e256d2e17317628f6b49aba8bc5456d8623f5f4..c54ef0726c9efb742e4c8fc3cc2c8a34b95fcf8f 100644 |
--- a/dart/runtime/bin/eventhandler_win.h |
+++ b/dart/runtime/bin/eventhandler_win.h |
@@ -29,6 +29,13 @@ 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. |
@@ -154,7 +161,7 @@ class OverlappedBuffer { |
// Abstract super class for holding information on listen and connected |
// sockets. |
-class Handle : public DescriptorInfoBase { |
+class Handle { |
public: |
enum Type { |
kFile, |
@@ -218,6 +225,7 @@ class Handle : public DescriptorInfoBase { |
EventHandlerImplementation* event_handler) = 0; |
HANDLE handle() { return handle_; } |
+ Dart_Port port() { return port_; } |
void Lock(); |
void Unlock(); |
@@ -230,6 +238,10 @@ class Handle : public DescriptorInfoBase { |
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 || |
@@ -238,6 +250,8 @@ class Handle : public DescriptorInfoBase { |
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); |
@@ -260,12 +274,15 @@ class Handle : public DescriptorInfoBase { |
kError = 4 |
}; |
- explicit Handle(intptr_t handle); |
+ explicit Handle(HANDLE handle); |
+ Handle(HANDLE handle, Dart_Port port); |
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_; |
@@ -281,12 +298,12 @@ class Handle : public DescriptorInfoBase { |
}; |
-class FileHandle : public DescriptorInfoSingleMixin<Handle> { |
+class FileHandle : public Handle { |
public: |
explicit FileHandle(HANDLE handle) |
- : DescriptorInfoSingleMixin(reinterpret_cast<intptr_t>(handle)) { |
- type_ = kFile; |
- } |
+ : Handle(handle) { type_ = kFile; } |
+ FileHandle(HANDLE handle, Dart_Port port) |
+ : Handle(handle, port) { type_ = kFile; } |
virtual void EnsureInitialized(EventHandlerImplementation* event_handler); |
virtual bool IsClosed(); |
@@ -322,10 +339,10 @@ class StdHandle : public FileHandle { |
}; |
-class DirectoryWatchHandle : public DescriptorInfoSingleMixin<Handle> { |
+class DirectoryWatchHandle : public Handle { |
public: |
DirectoryWatchHandle(HANDLE handle, int events, bool recursive) |
- : DescriptorInfoSingleMixin(reinterpret_cast<intptr_t>(handle)), |
+ : Handle(handle), |
events_(events), |
recursive_(recursive) { |
type_ = kDirectoryWatch; |
@@ -349,8 +366,11 @@ class SocketHandle : public Handle { |
SOCKET socket() const { return socket_; } |
protected: |
- explicit SocketHandle(intptr_t s) |
- : Handle(s), |
+ explicit SocketHandle(SOCKET s) |
+ : Handle(reinterpret_cast<HANDLE>(s)), |
+ socket_(s) {} |
+ SocketHandle(SOCKET s, Dart_Port port) |
+ : Handle(reinterpret_cast<HANDLE>(s), port), |
socket_(s) {} |
virtual void HandleIssueError(); |
@@ -361,14 +381,13 @@ class SocketHandle : public Handle { |
// Information on listen sockets. |
-class ListenSocket : public DescriptorInfoMultipleMixin<SocketHandle> { |
+class ListenSocket : public SocketHandle { |
public: |
- explicit ListenSocket(intptr_t s) : DescriptorInfoMultipleMixin(s), |
- AcceptEx_(NULL), |
- pending_accept_count_(0), |
- accepted_head_(NULL), |
- accepted_tail_(NULL), |
- accepted_count_(0) { |
+ explicit ListenSocket(SOCKET s) : SocketHandle(s), |
+ AcceptEx_(NULL), |
+ pending_accept_count_(0), |
+ accepted_head_(NULL), |
+ accepted_tail_(NULL) { |
type_ = kListenSocket; |
} |
virtual ~ListenSocket() { |
@@ -393,32 +412,22 @@ class ListenSocket : public DescriptorInfoMultipleMixin<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 DescriptorInfoSingleMixin<SocketHandle> { |
+class ClientSocket : public SocketHandle { |
public: |
- explicit ClientSocket(intptr_t s) : DescriptorInfoSingleMixin(s), |
+ explicit ClientSocket(SOCKET s) : SocketHandle(s), |
DisconnectEx_(NULL), |
next_(NULL), |
connected_(false), |
@@ -427,6 +436,15 @@ class ClientSocket : public DescriptorInfoSingleMixin<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()); |
@@ -468,9 +486,9 @@ class ClientSocket : public DescriptorInfoSingleMixin<SocketHandle> { |
}; |
-class DatagramSocket : public DescriptorInfoSingleMixin<SocketHandle> { |
+class DatagramSocket : public SocketHandle { |
public: |
- explicit DatagramSocket(intptr_t s) : DescriptorInfoSingleMixin(s) { |
+ explicit DatagramSocket(SOCKET s) : SocketHandle(s) { |
type_ = kDatagramSocket; |
} |
@@ -505,7 +523,6 @@ 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); |