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 RUNTIME_BIN_EVENTHANDLER_WIN_H_ | 5 #ifndef RUNTIME_BIN_EVENTHANDLER_WIN_H_ |
6 #define RUNTIME_BIN_EVENTHANDLER_WIN_H_ | 6 #define RUNTIME_BIN_EVENTHANDLER_WIN_H_ |
7 | 7 |
8 #if !defined(RUNTIME_BIN_EVENTHANDLER_H_) | 8 #if !defined(RUNTIME_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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 void NotifyReadThreadStarted(); | 284 void NotifyReadThreadStarted(); |
285 void WaitForReadThreadFinished(); | 285 void WaitForReadThreadFinished(); |
286 void NotifyReadThreadFinished(); | 286 void NotifyReadThreadFinished(); |
287 | 287 |
288 int flags_; | 288 int flags_; |
289 | 289 |
290 friend class ReferenceCounted<Handle>; | 290 friend class ReferenceCounted<Handle>; |
291 DISALLOW_COPY_AND_ASSIGN(Handle); | 291 DISALLOW_COPY_AND_ASSIGN(Handle); |
292 }; | 292 }; |
293 | 293 |
294 | |
295 class FileHandle : public DescriptorInfoSingleMixin<Handle> { | 294 class FileHandle : public DescriptorInfoSingleMixin<Handle> { |
296 public: | 295 public: |
297 explicit FileHandle(HANDLE handle) | 296 explicit FileHandle(HANDLE handle) |
298 : DescriptorInfoSingleMixin(reinterpret_cast<intptr_t>(handle), true) { | 297 : DescriptorInfoSingleMixin(reinterpret_cast<intptr_t>(handle), true) { |
299 type_ = kFile; | 298 type_ = kFile; |
300 } | 299 } |
301 | 300 |
302 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); | 301 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); |
303 virtual bool IsClosed(); | 302 virtual bool IsClosed(); |
304 | 303 |
305 private: | 304 private: |
306 DISALLOW_COPY_AND_ASSIGN(FileHandle); | 305 DISALLOW_COPY_AND_ASSIGN(FileHandle); |
307 }; | 306 }; |
308 | 307 |
309 | |
310 class StdHandle : public FileHandle { | 308 class StdHandle : public FileHandle { |
311 public: | 309 public: |
312 static StdHandle* Stdin(HANDLE handle); | 310 static StdHandle* Stdin(HANDLE handle); |
313 | 311 |
314 virtual void DoClose(); | 312 virtual void DoClose(); |
315 virtual intptr_t Write(const void* buffer, intptr_t num_bytes); | 313 virtual intptr_t Write(const void* buffer, intptr_t num_bytes); |
316 | 314 |
317 void WriteSyncCompleteAsync(); | 315 void WriteSyncCompleteAsync(); |
318 void RunWriteLoop(); | 316 void RunWriteLoop(); |
319 | 317 |
(...skipping 17 matching lines...) Expand all Loading... |
337 | 335 |
338 ThreadId thread_id_; | 336 ThreadId thread_id_; |
339 HANDLE thread_handle_; | 337 HANDLE thread_handle_; |
340 intptr_t thread_wrote_; | 338 intptr_t thread_wrote_; |
341 bool write_thread_exists_; | 339 bool write_thread_exists_; |
342 bool write_thread_running_; | 340 bool write_thread_running_; |
343 | 341 |
344 DISALLOW_COPY_AND_ASSIGN(StdHandle); | 342 DISALLOW_COPY_AND_ASSIGN(StdHandle); |
345 }; | 343 }; |
346 | 344 |
347 | |
348 class DirectoryWatchHandle : public DescriptorInfoSingleMixin<Handle> { | 345 class DirectoryWatchHandle : public DescriptorInfoSingleMixin<Handle> { |
349 public: | 346 public: |
350 DirectoryWatchHandle(HANDLE handle, int events, bool recursive) | 347 DirectoryWatchHandle(HANDLE handle, int events, bool recursive) |
351 : DescriptorInfoSingleMixin(reinterpret_cast<intptr_t>(handle), true), | 348 : DescriptorInfoSingleMixin(reinterpret_cast<intptr_t>(handle), true), |
352 events_(events), | 349 events_(events), |
353 recursive_(recursive) { | 350 recursive_(recursive) { |
354 type_ = kDirectoryWatch; | 351 type_ = kDirectoryWatch; |
355 } | 352 } |
356 | 353 |
357 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); | 354 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); |
358 virtual bool IsClosed(); | 355 virtual bool IsClosed(); |
359 | 356 |
360 virtual bool IssueRead(); | 357 virtual bool IssueRead(); |
361 | 358 |
362 void Stop(); | 359 void Stop(); |
363 | 360 |
364 private: | 361 private: |
365 int events_; | 362 int events_; |
366 bool recursive_; | 363 bool recursive_; |
367 | 364 |
368 DISALLOW_COPY_AND_ASSIGN(DirectoryWatchHandle); | 365 DISALLOW_COPY_AND_ASSIGN(DirectoryWatchHandle); |
369 }; | 366 }; |
370 | 367 |
371 | |
372 class SocketHandle : public Handle { | 368 class SocketHandle : public Handle { |
373 public: | 369 public: |
374 SOCKET socket() const { return socket_; } | 370 SOCKET socket() const { return socket_; } |
375 | 371 |
376 protected: | 372 protected: |
377 explicit SocketHandle(intptr_t s) : Handle(s), socket_(s) {} | 373 explicit SocketHandle(intptr_t s) : Handle(s), socket_(s) {} |
378 | 374 |
379 virtual void HandleIssueError(); | 375 virtual void HandleIssueError(); |
380 | 376 |
381 private: | 377 private: |
382 const SOCKET socket_; | 378 const SOCKET socket_; |
383 | 379 |
384 DISALLOW_COPY_AND_ASSIGN(SocketHandle); | 380 DISALLOW_COPY_AND_ASSIGN(SocketHandle); |
385 }; | 381 }; |
386 | 382 |
387 | |
388 // Information on listen sockets. | 383 // Information on listen sockets. |
389 class ListenSocket : public DescriptorInfoMultipleMixin<SocketHandle> { | 384 class ListenSocket : public DescriptorInfoMultipleMixin<SocketHandle> { |
390 public: | 385 public: |
391 explicit ListenSocket(intptr_t s) | 386 explicit ListenSocket(intptr_t s) |
392 : DescriptorInfoMultipleMixin(s, true), | 387 : DescriptorInfoMultipleMixin(s, true), |
393 AcceptEx_(NULL), | 388 AcceptEx_(NULL), |
394 pending_accept_count_(0), | 389 pending_accept_count_(0), |
395 accepted_head_(NULL), | 390 accepted_head_(NULL), |
396 accepted_tail_(NULL), | 391 accepted_tail_(NULL), |
397 accepted_count_(0) { | 392 accepted_count_(0) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 ClientSocket* accepted_head_; | 429 ClientSocket* accepted_head_; |
435 ClientSocket* accepted_tail_; | 430 ClientSocket* accepted_tail_; |
436 | 431 |
437 // The number of accepted connections which are waiting to be removed from | 432 // The number of accepted connections which are waiting to be removed from |
438 // this queue and processed by dart isolates. | 433 // this queue and processed by dart isolates. |
439 int accepted_count_; | 434 int accepted_count_; |
440 | 435 |
441 DISALLOW_COPY_AND_ASSIGN(ListenSocket); | 436 DISALLOW_COPY_AND_ASSIGN(ListenSocket); |
442 }; | 437 }; |
443 | 438 |
444 | |
445 // Information on connected sockets. | 439 // Information on connected sockets. |
446 class ClientSocket : public DescriptorInfoSingleMixin<SocketHandle> { | 440 class ClientSocket : public DescriptorInfoSingleMixin<SocketHandle> { |
447 public: | 441 public: |
448 explicit ClientSocket(intptr_t s) | 442 explicit ClientSocket(intptr_t s) |
449 : DescriptorInfoSingleMixin(s, true), | 443 : DescriptorInfoSingleMixin(s, true), |
450 DisconnectEx_(NULL), | 444 DisconnectEx_(NULL), |
451 next_(NULL), | 445 next_(NULL), |
452 connected_(false), | 446 connected_(false), |
453 closed_(false) { | 447 closed_(false) { |
454 LoadDisconnectEx(); | 448 LoadDisconnectEx(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 bool connected_; | 491 bool connected_; |
498 bool closed_; | 492 bool closed_; |
499 | 493 |
500 #if defined(DEBUG) | 494 #if defined(DEBUG) |
501 static intptr_t disconnecting_; | 495 static intptr_t disconnecting_; |
502 #endif | 496 #endif |
503 | 497 |
504 DISALLOW_COPY_AND_ASSIGN(ClientSocket); | 498 DISALLOW_COPY_AND_ASSIGN(ClientSocket); |
505 }; | 499 }; |
506 | 500 |
507 | |
508 class DatagramSocket : public DescriptorInfoSingleMixin<SocketHandle> { | 501 class DatagramSocket : public DescriptorInfoSingleMixin<SocketHandle> { |
509 public: | 502 public: |
510 explicit DatagramSocket(intptr_t s) : DescriptorInfoSingleMixin(s, true) { | 503 explicit DatagramSocket(intptr_t s) : DescriptorInfoSingleMixin(s, true) { |
511 type_ = kDatagramSocket; | 504 type_ = kDatagramSocket; |
512 } | 505 } |
513 | 506 |
514 virtual ~DatagramSocket() { | 507 virtual ~DatagramSocket() { |
515 // Don't delete this object until all pending requests have been handled. | 508 // Don't delete this object until all pending requests have been handled. |
516 ASSERT(!HasPendingRead()); | 509 ASSERT(!HasPendingRead()); |
517 ASSERT(!HasPendingWrite()); | 510 ASSERT(!HasPendingWrite()); |
518 } | 511 } |
519 | 512 |
520 // Internal interface used by the event handler. | 513 // Internal interface used by the event handler. |
521 virtual bool IssueRecvFrom(); | 514 virtual bool IssueRecvFrom(); |
522 virtual bool IssueSendTo(sockaddr* sa, socklen_t sa_len); | 515 virtual bool IssueSendTo(sockaddr* sa, socklen_t sa_len); |
523 | 516 |
524 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); | 517 virtual void EnsureInitialized(EventHandlerImplementation* event_handler); |
525 virtual void DoClose(); | 518 virtual void DoClose(); |
526 virtual bool IsClosed(); | 519 virtual bool IsClosed(); |
527 | 520 |
528 private: | 521 private: |
529 DISALLOW_COPY_AND_ASSIGN(DatagramSocket); | 522 DISALLOW_COPY_AND_ASSIGN(DatagramSocket); |
530 }; | 523 }; |
531 | 524 |
532 | |
533 // Event handler. | 525 // Event handler. |
534 class EventHandlerImplementation { | 526 class EventHandlerImplementation { |
535 public: | 527 public: |
536 EventHandlerImplementation(); | 528 EventHandlerImplementation(); |
537 virtual ~EventHandlerImplementation(); | 529 virtual ~EventHandlerImplementation(); |
538 | 530 |
539 void SendData(intptr_t id, Dart_Port dart_port, int64_t data); | 531 void SendData(intptr_t id, Dart_Port dart_port, int64_t data); |
540 void Start(EventHandler* handler); | 532 void Start(EventHandler* handler); |
541 void Shutdown(); | 533 void Shutdown(); |
542 | 534 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 bool shutdown_; | 566 bool shutdown_; |
575 HANDLE completion_port_; | 567 HANDLE completion_port_; |
576 | 568 |
577 DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation); | 569 DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation); |
578 }; | 570 }; |
579 | 571 |
580 } // namespace bin | 572 } // namespace bin |
581 } // namespace dart | 573 } // namespace dart |
582 | 574 |
583 #endif // RUNTIME_BIN_EVENTHANDLER_WIN_H_ | 575 #endif // RUNTIME_BIN_EVENTHANDLER_WIN_H_ |
OLD | NEW |