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

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

Issue 879353003: Introduce optional 'bool shared' parameter to ServerSocket.bind() ... (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Part 3: Other platforms (preliminary) Created 5 years, 10 months 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
OLDNEW
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 11 matching lines...) Expand all
22 22
23 // Forward declarations. 23 // Forward declarations.
24 class EventHandlerImplementation; 24 class EventHandlerImplementation;
25 class Handle; 25 class Handle;
26 class FileHandle; 26 class FileHandle;
27 class SocketHandle; 27 class SocketHandle;
28 class ClientSocket; 28 class ClientSocket;
29 class ListenSocket; 29 class ListenSocket;
30 30
31 31
32 struct InterruptMessage {
33 intptr_t id;
34 Dart_Port dart_port;
35 int64_t data;
36 };
37
38
39 // An OverlappedBuffer encapsulates the OVERLAPPED structure and the 32 // An OverlappedBuffer encapsulates the OVERLAPPED structure and the
40 // associated data buffer. For accept it also contains the pre-created 33 // associated data buffer. For accept it also contains the pre-created
41 // socket for the client. 34 // socket for the client.
42 class OverlappedBuffer { 35 class OverlappedBuffer {
43 public: 36 public:
44 enum Operation { 37 enum Operation {
45 kAccept, kRead, kRecvFrom, kWrite, kSendTo, kDisconnect, kConnect 38 kAccept, kRead, kRecvFrom, kWrite, kSendTo, kDisconnect, kConnect
46 }; 39 };
47 40
48 static OverlappedBuffer* AllocateAcceptBuffer(int buffer_size); 41 static OverlappedBuffer* AllocateAcceptBuffer(int buffer_size);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 147
155 // Buffer for recv/send/AcceptEx. This must be at the end of the 148 // Buffer for recv/send/AcceptEx. This must be at the end of the
156 // object as the object is allocated larger than it's definition 149 // object as the object is allocated larger than it's definition
157 // indicate to extend this array. 150 // indicate to extend this array.
158 uint8_t buffer_data_[1]; 151 uint8_t buffer_data_[1];
159 }; 152 };
160 153
161 154
162 // Abstract super class for holding information on listen and connected 155 // Abstract super class for holding information on listen and connected
163 // sockets. 156 // sockets.
164 class Handle { 157 class Handle : public DescriptorInfo {
165 public: 158 public:
166 enum Type { 159 enum Type {
167 kFile, 160 kFile,
168 kStd, 161 kStd,
169 kDirectoryWatch, 162 kDirectoryWatch,
170 kClientSocket, 163 kClientSocket,
171 kListenSocket, 164 kListenSocket,
172 kDatagramSocket 165 kDatagramSocket
173 }; 166 };
174 167
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 bool IsError() { return (flags_ & (1 << kError)) != 0; } 211 bool IsError() { return (flags_ & (1 << kError)) != 0; }
219 void MarkClosing() { flags_ |= (1 << kClosing); } 212 void MarkClosing() { flags_ |= (1 << kClosing); }
220 void MarkClosedRead() { flags_ |= (1 << kCloseRead); } 213 void MarkClosedRead() { flags_ |= (1 << kCloseRead); }
221 void MarkClosedWrite() { flags_ |= (1 << kCloseWrite); } 214 void MarkClosedWrite() { flags_ |= (1 << kCloseWrite); }
222 void MarkError() { flags_ |= (1 << kError); } 215 void MarkError() { flags_ |= (1 << kError); }
223 216
224 virtual void EnsureInitialized( 217 virtual void EnsureInitialized(
225 EventHandlerImplementation* event_handler) = 0; 218 EventHandlerImplementation* event_handler) = 0;
226 219
227 HANDLE handle() { return handle_; } 220 HANDLE handle() { return handle_; }
228 Dart_Port port() { return port_; }
229 221
230 void Lock(); 222 void Lock();
231 void Unlock(); 223 void Unlock();
232 224
233 bool CreateCompletionPort(HANDLE completion_port); 225 bool CreateCompletionPort(HANDLE completion_port);
234 226
235 void Close(); 227 void Close();
236 virtual void DoClose(); 228 virtual void DoClose();
237 virtual bool IsClosed() = 0; 229 virtual bool IsClosed() = 0;
238 230
239 bool IsHandleClosed() const { return handle_ == INVALID_HANDLE_VALUE; } 231 bool IsHandleClosed() const { return handle_ == INVALID_HANDLE_VALUE; }
240 232
241 void SetPortAndMask(Dart_Port port, intptr_t mask) {
242 port_ = port;
243 mask_ = mask;
244 }
245 Type type() { return type_; } 233 Type type() { return type_; }
246 bool is_file() { return type_ == kFile; } 234 bool is_file() { return type_ == kFile; }
247 bool is_socket() { return type_ == kListenSocket || 235 bool is_socket() { return type_ == kListenSocket ||
248 type_ == kClientSocket || 236 type_ == kClientSocket ||
249 type_ == kDatagramSocket; } 237 type_ == kDatagramSocket; }
250 bool is_listen_socket() { return type_ == kListenSocket; } 238 bool is_listen_socket() { return type_ == kListenSocket; }
251 bool is_client_socket() { return type_ == kClientSocket; } 239 bool is_client_socket() { return type_ == kClientSocket; }
252 bool is_datagram_socket() { return type_ == kDatagramSocket; } 240 bool is_datagram_socket() { return type_ == kDatagramSocket; }
253 void set_mask(intptr_t mask) { mask_ = mask; }
254 intptr_t mask() { return mask_; }
255 241
256 void MarkDoesNotSupportOverlappedIO() { 242 void MarkDoesNotSupportOverlappedIO() {
257 flags_ |= (1 << kDoesNotSupportOverlappedIO); 243 flags_ |= (1 << kDoesNotSupportOverlappedIO);
258 } 244 }
259 bool SupportsOverlappedIO() { 245 bool SupportsOverlappedIO() {
260 return (flags_ & (1 << kDoesNotSupportOverlappedIO)) == 0; 246 return (flags_ & (1 << kDoesNotSupportOverlappedIO)) == 0;
261 } 247 }
262 248
263 void ReadSyncCompleteAsync(); 249 void ReadSyncCompleteAsync();
264 250
265 DWORD last_error() { return last_error_; } 251 DWORD last_error() { return last_error_; }
266 void set_last_error(DWORD last_error) { last_error_ = last_error; } 252 void set_last_error(DWORD last_error) { last_error_ = last_error; }
267 253
268 protected: 254 protected:
269 enum Flags { 255 enum Flags {
270 kClosing = 0, 256 kClosing = 0,
271 kCloseRead = 1, 257 kCloseRead = 1,
272 kCloseWrite = 2, 258 kCloseWrite = 2,
273 kDoesNotSupportOverlappedIO = 3, 259 kDoesNotSupportOverlappedIO = 3,
274 kError = 4 260 kError = 4
275 }; 261 };
276 262
277 explicit Handle(HANDLE handle); 263 explicit Handle(intptr_t handle);
278 Handle(HANDLE handle, Dart_Port port);
279 264
280 virtual void HandleIssueError(); 265 virtual void HandleIssueError();
281 266
282 Type type_; 267 Type type_;
283 HANDLE handle_; 268 HANDLE handle_;
284 Dart_Port port_; // Dart port to communicate events for this socket.
285 intptr_t mask_; // Mask of events to report through the port.
286 HANDLE completion_port_; 269 HANDLE completion_port_;
287 EventHandlerImplementation* event_handler_; 270 EventHandlerImplementation* event_handler_;
288 271
289 OverlappedBuffer* data_ready_; // Buffer for data ready to be read. 272 OverlappedBuffer* data_ready_; // Buffer for data ready to be read.
290 OverlappedBuffer* pending_read_; // Buffer for pending read. 273 OverlappedBuffer* pending_read_; // Buffer for pending read.
291 OverlappedBuffer* pending_write_; // Buffer for pending write 274 OverlappedBuffer* pending_write_; // Buffer for pending write
292 275
293 DWORD last_error_; 276 DWORD last_error_;
294 277
295 private: 278 private:
296 int flags_; 279 int flags_;
297 CRITICAL_SECTION cs_; // Critical section protecting this object. 280 CRITICAL_SECTION cs_; // Critical section protecting this object.
298 }; 281 };
299 282
300 283
301 class FileHandle : public Handle { 284 class FileHandle : public DescriptorInfoSingle<Handle> {
302 public: 285 public:
303 explicit FileHandle(HANDLE handle) 286 explicit FileHandle(HANDLE handle)
304 : Handle(handle) { type_ = kFile; } 287 : DescriptorInfoSingle(reinterpret_cast<intptr_t>(handle)) {
305 FileHandle(HANDLE handle, Dart_Port port) 288 type_ = kFile;
306 : Handle(handle, port) { type_ = kFile; } 289 }
307 290
308 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); 291 virtual void EnsureInitialized(EventHandlerImplementation* event_handler);
309 virtual bool IsClosed(); 292 virtual bool IsClosed();
310 }; 293 };
311 294
312 295
313 class StdHandle : public FileHandle { 296 class StdHandle : public FileHandle {
314 public: 297 public:
315 explicit StdHandle(HANDLE handle) 298 explicit StdHandle(HANDLE handle)
316 : FileHandle(handle), 299 : FileHandle(handle),
(...skipping 15 matching lines...) Expand all
332 void RunWriteLoop(); 315 void RunWriteLoop();
333 316
334 private: 317 private:
335 intptr_t thread_wrote_; 318 intptr_t thread_wrote_;
336 bool write_thread_exists_; 319 bool write_thread_exists_;
337 bool write_thread_running_; 320 bool write_thread_running_;
338 Monitor* write_monitor_; 321 Monitor* write_monitor_;
339 }; 322 };
340 323
341 324
342 class DirectoryWatchHandle : public Handle { 325 class DirectoryWatchHandle : public DescriptorInfoSingle<Handle> {
343 public: 326 public:
344 DirectoryWatchHandle(HANDLE handle, int events, bool recursive) 327 DirectoryWatchHandle(HANDLE handle, int events, bool recursive)
345 : Handle(handle), 328 : DescriptorInfoSingle(reinterpret_cast<intptr_t>(handle)),
346 events_(events), 329 events_(events),
347 recursive_(recursive) { 330 recursive_(recursive) {
348 type_ = kDirectoryWatch; 331 type_ = kDirectoryWatch;
349 } 332 }
350 333
351 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); 334 virtual void EnsureInitialized(EventHandlerImplementation* event_handler);
352 virtual bool IsClosed(); 335 virtual bool IsClosed();
353 336
354 virtual bool IssueRead(); 337 virtual bool IssueRead();
355 338
356 void Stop(); 339 void Stop();
357 340
358 private: 341 private:
359 int events_; 342 int events_;
360 bool recursive_; 343 bool recursive_;
361 }; 344 };
362 345
363 346
364 class SocketHandle : public Handle { 347 class SocketHandle : public Handle {
365 public: 348 public:
366 SOCKET socket() const { return socket_; } 349 SOCKET socket() const { return socket_; }
367 350
368 protected: 351 protected:
369 explicit SocketHandle(SOCKET s) 352 explicit SocketHandle(intptr_t s)
370 : Handle(reinterpret_cast<HANDLE>(s)), 353 : Handle(s),
371 socket_(s) {}
372 SocketHandle(SOCKET s, Dart_Port port)
373 : Handle(reinterpret_cast<HANDLE>(s), port),
374 socket_(s) {} 354 socket_(s) {}
375 355
376 virtual void HandleIssueError(); 356 virtual void HandleIssueError();
377 357
378 private: 358 private:
379 const SOCKET socket_; 359 const SOCKET socket_;
380 }; 360 };
381 361
382 362
383 // Information on listen sockets. 363 // Information on listen sockets.
384 class ListenSocket : public SocketHandle { 364 class ListenSocket : public DescriptorInfoMultiple<SocketHandle> {
385 public: 365 public:
386 explicit ListenSocket(SOCKET s) : SocketHandle(s), 366 explicit ListenSocket(intptr_t s) : DescriptorInfoMultiple(s),
387 AcceptEx_(NULL), 367 AcceptEx_(NULL),
388 pending_accept_count_(0), 368 pending_accept_count_(0),
389 accepted_head_(NULL), 369 accepted_head_(NULL),
390 accepted_tail_(NULL) { 370 accepted_tail_(NULL) {
391 type_ = kListenSocket; 371 type_ = kListenSocket;
392 } 372 }
393 virtual ~ListenSocket() { 373 virtual ~ListenSocket() {
394 ASSERT(!HasPendingAccept()); 374 ASSERT(!HasPendingAccept());
395 ASSERT(accepted_head_ == NULL); 375 ASSERT(accepted_head_ == NULL);
396 ASSERT(accepted_tail_ == NULL); 376 ASSERT(accepted_tail_ == NULL);
397 } 377 }
398 378
399 // Socket interface exposing normal socket operations. 379 // Socket interface exposing normal socket operations.
400 ClientSocket* Accept(); 380 ClientSocket* Accept();
(...skipping 17 matching lines...) Expand all
418 LPFN_ACCEPTEX AcceptEx_; 398 LPFN_ACCEPTEX AcceptEx_;
419 int pending_accept_count_; 399 int pending_accept_count_;
420 // Linked list of accepted connections provided by completion code. Ready to 400 // Linked list of accepted connections provided by completion code. Ready to
421 // be handed over through accept. 401 // be handed over through accept.
422 ClientSocket* accepted_head_; 402 ClientSocket* accepted_head_;
423 ClientSocket* accepted_tail_; 403 ClientSocket* accepted_tail_;
424 }; 404 };
425 405
426 406
427 // Information on connected sockets. 407 // Information on connected sockets.
428 class ClientSocket : public SocketHandle { 408 class ClientSocket : public DescriptorInfoSingle<SocketHandle> {
429 public: 409 public:
430 explicit ClientSocket(SOCKET s) : SocketHandle(s), 410 explicit ClientSocket(intptr_t s) : DescriptorInfoSingle(s),
431 DisconnectEx_(NULL), 411 DisconnectEx_(NULL),
432 next_(NULL), 412 next_(NULL),
433 connected_(false), 413 connected_(false),
434 closed_(false) { 414 closed_(false) {
435 LoadDisconnectEx(); 415 LoadDisconnectEx();
436 type_ = kClientSocket; 416 type_ = kClientSocket;
437 } 417 }
438 418
439 ClientSocket(SOCKET s, Dart_Port port) : SocketHandle(s, port),
440 DisconnectEx_(NULL),
441 next_(NULL),
442 connected_(false),
443 closed_(false) {
444 LoadDisconnectEx();
445 type_ = kClientSocket;
446 }
447
448 virtual ~ClientSocket() { 419 virtual ~ClientSocket() {
449 // Don't delete this object until all pending requests have been handled. 420 // Don't delete this object until all pending requests have been handled.
450 ASSERT(!HasPendingRead()); 421 ASSERT(!HasPendingRead());
451 ASSERT(!HasPendingWrite()); 422 ASSERT(!HasPendingWrite());
452 ASSERT(next_ == NULL); 423 ASSERT(next_ == NULL);
453 ASSERT(closed_ == true); 424 ASSERT(closed_ == true);
454 } 425 }
455 426
456 void Shutdown(int how); 427 void Shutdown(int how);
457 428
(...skipping 21 matching lines...) Expand all
479 private: 450 private:
480 bool LoadDisconnectEx(); 451 bool LoadDisconnectEx();
481 452
482 LPFN_DISCONNECTEX DisconnectEx_; 453 LPFN_DISCONNECTEX DisconnectEx_;
483 ClientSocket* next_; 454 ClientSocket* next_;
484 bool connected_; 455 bool connected_;
485 bool closed_; 456 bool closed_;
486 }; 457 };
487 458
488 459
489 class DatagramSocket : public SocketHandle { 460 class DatagramSocket : public DescriptorInfoSingle<SocketHandle> {
490 public: 461 public:
491 explicit DatagramSocket(SOCKET s) : SocketHandle(s) { 462 explicit DatagramSocket(intptr_t s) : DescriptorInfoSingle(s) {
492 type_ = kDatagramSocket; 463 type_ = kDatagramSocket;
493 } 464 }
494 465
495 virtual ~DatagramSocket() { 466 virtual ~DatagramSocket() {
496 // Don't delete this object until all pending requests have been handled. 467 // Don't delete this object until all pending requests have been handled.
497 ASSERT(!HasPendingRead()); 468 ASSERT(!HasPendingRead());
498 ASSERT(!HasPendingWrite()); 469 ASSERT(!HasPendingWrite());
499 } 470 }
500 471
501 // Internal interface used by the event handler. 472 // Internal interface used by the event handler.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 512
542 TimeoutQueue timeout_queue_; // Time for next timeout. 513 TimeoutQueue timeout_queue_; // Time for next timeout.
543 bool shutdown_; 514 bool shutdown_;
544 HANDLE completion_port_; 515 HANDLE completion_port_;
545 }; 516 };
546 517
547 } // namespace bin 518 } // namespace bin
548 } // namespace dart 519 } // namespace dart
549 520
550 #endif // BIN_EVENTHANDLER_WIN_H_ 521 #endif // BIN_EVENTHANDLER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698