Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: runtime/bin/eventhandler_win.h

Issue 8503006: Fix handling of async IO from pipes on Windows (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from ager@ Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/eventhandler_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 #include <winsock2.h> 8 #include <winsock2.h>
9 #include <mswsock.h> 9 #include <mswsock.h>
10 10
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 int Write(const void* buffer, int num_bytes); 145 int Write(const void* buffer, int num_bytes);
146 146
147 // Internal interface used by the event handler. 147 // Internal interface used by the event handler.
148 virtual bool IssueRead(); 148 virtual bool IssueRead();
149 virtual bool IssueWrite(); 149 virtual bool IssueWrite();
150 bool HasPendingRead(); 150 bool HasPendingRead();
151 bool HasPendingWrite(); 151 bool HasPendingWrite();
152 void ReadComplete(IOBuffer* buffer); 152 void ReadComplete(IOBuffer* buffer);
153 void WriteComplete(IOBuffer* buffer); 153 void WriteComplete(IOBuffer* buffer);
154 154
155 bool IsClosing() { return (flags_ & (1 << kClosing)) != 0; }
156 bool IsClosedRead() { return (flags_ & (1 << kCloseRead)) != 0; }
157 bool IsClosedWrite() { return (flags_ & (1 << kCloseWrite)) != 0; }
158 void MarkClosing() { flags_ |= (1 << kClosing); }
159 void MarkClosedRead() { flags_ |= (1 << kCloseRead); }
160 void MarkClosedWrite() { flags_ |= (1 << kCloseWrite); }
161
155 virtual void EnsureInitialized( 162 virtual void EnsureInitialized(
156 EventHandlerImplementation* event_handler) = 0; 163 EventHandlerImplementation* event_handler) = 0;
157 164
158 HANDLE handle() { return handle_; } 165 HANDLE handle() { return handle_; }
159 Dart_Port port() { return port_; } 166 Dart_Port port() { return port_; }
160 EventHandlerImplementation* event_handler() { return event_handler_; } 167 EventHandlerImplementation* event_handler() { return event_handler_; }
161 168
162 void Lock(); 169 void Lock();
163 void Unlock(); 170 void Unlock();
164 171
165 bool CreateCompletionPort(HANDLE completion_port); 172 bool CreateCompletionPort(HANDLE completion_port);
166 173
167 void close(); 174 void close();
168 virtual bool IsClosed() = 0; 175 virtual bool IsClosed() = 0;
169 176
170 void SetPortAndMask(Dart_Port port, intptr_t mask) { 177 void SetPortAndMask(Dart_Port port, intptr_t mask) {
171 port_ = port; 178 port_ = port;
172 mask_ = mask; 179 mask_ = mask;
173 } 180 }
174 Type type() { return type_; } 181 Type type() { return type_; }
175 bool is_file() { return type_ == kFile; } 182 bool is_file() { return type_ == kFile; }
176 bool is_socket() { return type_ == kListenSocket || type_ == kClientSocket; } 183 bool is_socket() { return type_ == kListenSocket || type_ == kClientSocket; }
177 bool is_listen_socket() { return type_ == kListenSocket; } 184 bool is_listen_socket() { return type_ == kListenSocket; }
178 bool is_client_socket() { return type_ == kClientSocket; } 185 bool is_client_socket() { return type_ == kClientSocket; }
179 intptr_t mask() { return mask_; } 186 intptr_t mask() { return mask_; }
180 187
181 bool is_closing() { return closing_; } 188 protected:
189 enum Flags {
190 kClosing = 0,
191 kCloseRead = 1,
192 kCloseWrite = 2
193 };
182 194
183 protected:
184 explicit Handle(HANDLE handle); 195 explicit Handle(HANDLE handle);
185 Handle(HANDLE handle, Dart_Port port); 196 Handle(HANDLE handle, Dart_Port port);
186 197
187 virtual void AfterClose() = 0; 198 virtual void AfterClose() = 0;
188 199
189 Type type_; 200 Type type_;
190 HANDLE handle_; 201 HANDLE handle_;
191 bool closing_; // Is this handle in the process of closing?
192 Dart_Port port_; // Dart port to communicate events for this socket. 202 Dart_Port port_; // Dart port to communicate events for this socket.
193 intptr_t mask_; // Mask of events to report through the port. 203 intptr_t mask_; // Mask of events to report through the port.
194 HANDLE completion_port_; 204 HANDLE completion_port_;
195 CRITICAL_SECTION cs_; // Critical section protecting this object.
196 EventHandlerImplementation* event_handler_; 205 EventHandlerImplementation* event_handler_;
197 206
198 IOBuffer* data_ready_; // IO buffer for data ready to be read. 207 IOBuffer* data_ready_; // IO buffer for data ready to be read.
199 IOBuffer* pending_read_; // IO buffer for pending read. 208 IOBuffer* pending_read_; // IO buffer for pending read.
200 IOBuffer* pending_write_; // IO buffer for pending write 209 IOBuffer* pending_write_; // IO buffer for pending write
210
211 private:
212 int flags_;
213 CRITICAL_SECTION cs_; // Critical section protecting this object.
201 }; 214 };
202 215
203 216
204 class FileHandle : public Handle { 217 class FileHandle : public Handle {
205 public: 218 public:
206 explicit FileHandle(HANDLE handle) 219 explicit FileHandle(HANDLE handle)
207 : Handle(reinterpret_cast<HANDLE>(handle)) { type_ = kFile; } 220 : Handle(reinterpret_cast<HANDLE>(handle)) { type_ = kFile; }
208 FileHandle(HANDLE handle, Dart_Port port) 221 FileHandle(HANDLE handle, Dart_Port port)
209 : Handle(reinterpret_cast<HANDLE>(handle), port) { type_ = kFile; } 222 : Handle(reinterpret_cast<HANDLE>(handle), port) { type_ = kFile; }
210 223
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // Linked list of accepted connections provided by completion code. Ready to 279 // Linked list of accepted connections provided by completion code. Ready to
267 // be handed over through accept. 280 // be handed over through accept.
268 ClientSocket* accepted_head_; 281 ClientSocket* accepted_head_;
269 ClientSocket* accepted_tail_; 282 ClientSocket* accepted_tail_;
270 }; 283 };
271 284
272 285
273 // Information on connected sockets. 286 // Information on connected sockets.
274 class ClientSocket : public SocketHandle { 287 class ClientSocket : public SocketHandle {
275 public: 288 public:
276 explicit ClientSocket(SOCKET s) 289 explicit ClientSocket(SOCKET s) : SocketHandle(s), next_(NULL) {
277 : SocketHandle(s), 290 type_ = kClientSocket;
278 next_(NULL), 291 }
279 flags_(0) { type_ = kClientSocket; }
280 292
281 ClientSocket(SOCKET s, Dart_Port port) 293 ClientSocket(SOCKET s, Dart_Port port) : SocketHandle(s, port), next_(NULL) {
282 : SocketHandle(s, port), 294 type_ = kClientSocket;
283 next_(NULL), 295 }
284 flags_(0) { type_ = kClientSocket; }
285 296
286 virtual ~ClientSocket() { 297 virtual ~ClientSocket() {
287 // Don't delete this object until all pending requests have been handled. 298 // Don't delete this object until all pending requests have been handled.
288 ASSERT(!HasPendingRead()); 299 ASSERT(!HasPendingRead());
289 ASSERT(!HasPendingWrite()); 300 ASSERT(!HasPendingWrite());
290 ASSERT(next_ == NULL); 301 ASSERT(next_ == NULL);
291 }; 302 };
292 303
293 void Shutdown(int how); 304 void Shutdown(int how);
294 bool IsClosedRead() { return (flags_ & (1 << kCloseRead)) != 0; }
295 bool IsClosedWrite() { return (flags_ & (1 << kCloseWrite)) != 0; }
296
297 void MarkClosedRead() { flags_ |= (1 << kCloseRead); }
298 void MarkClosedWrite() { flags_ |= (1 << kCloseWrite); }
299 305
300 // Internal interface used by the event handler. 306 // Internal interface used by the event handler.
301 virtual bool IssueRead(); 307 virtual bool IssueRead();
302 virtual bool IssueWrite(); 308 virtual bool IssueWrite();
303 309
304 virtual void EnsureInitialized( 310 virtual void EnsureInitialized(
305 EventHandlerImplementation* event_handler); 311 EventHandlerImplementation* event_handler);
306 virtual bool IsClosed(); 312 virtual bool IsClosed();
307 313
308 ClientSocket* next() { return next_; } 314 ClientSocket* next() { return next_; }
309 void set_next(ClientSocket* next) { next_ = next; } 315 void set_next(ClientSocket* next) { next_ = next; }
310 316
311 private: 317 private:
312 enum Flags {
313 kCloseRead = 0,
314 kCloseWrite = 1
315 };
316
317 virtual void AfterClose(); 318 virtual void AfterClose();
318 319
319 ClientSocket* next_; 320 ClientSocket* next_;
320 int flags_;
321 }; 321 };
322 322
323 323
324 // Event handler. 324 // Event handler.
325 class EventHandlerImplementation { 325 class EventHandlerImplementation {
326 public: 326 public:
327 EventHandlerImplementation(); 327 EventHandlerImplementation();
328 virtual ~EventHandlerImplementation() {} 328 virtual ~EventHandlerImplementation() {}
329 329
330 void SendData(intptr_t id, Dart_Port dart_port, intptr_t data); 330 void SendData(intptr_t id, Dart_Port dart_port, intptr_t data);
331 void StartEventHandler(); 331 void StartEventHandler();
332 332
333 DWORD GetTimeout(); 333 DWORD GetTimeout();
334 void HandleInterrupt(InterruptMessage* msg); 334 void HandleInterrupt(InterruptMessage* msg);
335 void HandleTimeout(); 335 void HandleTimeout();
336 void HandleAccept(ListenSocket* listen_socket, IOBuffer* buffer); 336 void HandleAccept(ListenSocket* listen_socket, IOBuffer* buffer);
337 void HandleClosed(Handle* handle); 337 void HandleClosed(Handle* handle);
338 void HandleRead(ClientSocket* client_socket, int bytes, IOBuffer* buffer); 338 void HandleRead(Handle* handle, int bytes, IOBuffer* buffer);
339 void HandleWrite(ClientSocket* client_socket, int bytes, IOBuffer* buffer); 339 void HandleWrite(Handle* handle, int bytes, IOBuffer* buffer);
340 void HandleClose(ClientSocket* client_socket); 340 void HandleClose(ClientSocket* client_socket);
341 void HandleIOCompletion(DWORD bytes, ULONG_PTR key, OVERLAPPED* overlapped); 341 void HandleIOCompletion(DWORD bytes, ULONG_PTR key, OVERLAPPED* overlapped);
342 342
343 HANDLE completion_port() { return completion_port_; } 343 HANDLE completion_port() { return completion_port_; }
344 344
345 private: 345 private:
346 ClientSocket* client_sockets_head_; 346 ClientSocket* client_sockets_head_;
347 347
348 int64_t timeout_; // Time for next timeout. 348 int64_t timeout_; // Time for next timeout.
349 Dart_Port timeout_port_; 349 Dart_Port timeout_port_;
350 HANDLE completion_port_; 350 HANDLE completion_port_;
351 }; 351 };
352 352
353 353
354 #endif // BIN_EVENTHANDLER_WIN_H_ 354 #endif // BIN_EVENTHANDLER_WIN_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/eventhandler_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698