| 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 #include "bin/eventhandler.h" | 5 #include "bin/eventhandler.h" |
| 6 | 6 |
| 7 #include <process.h> | 7 #include <process.h> |
| 8 #include <winsock2.h> | 8 #include <winsock2.h> |
| 9 #include <ws2tcpip.h> | 9 #include <ws2tcpip.h> |
| 10 #include <mswsock.h> | 10 #include <mswsock.h> |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 handle->EnsureInitialized(this); | 637 handle->EnsureInitialized(this); |
| 638 | 638 |
| 639 Handle::ScopedLock lock(handle); | 639 Handle::ScopedLock lock(handle); |
| 640 | 640 |
| 641 // If the data available callback has been requested and data are | 641 // If the data available callback has been requested and data are |
| 642 // available post it immediately. Otherwise make sure that a pending | 642 // available post it immediately. Otherwise make sure that a pending |
| 643 // read is issued unless the socket is already closed for read. | 643 // read is issued unless the socket is already closed for read. |
| 644 if ((msg->data & (1 << kInEvent)) != 0) { | 644 if ((msg->data & (1 << kInEvent)) != 0) { |
| 645 if (handle->Available() > 0) { | 645 if (handle->Available() > 0) { |
| 646 int event_mask = (1 << kInEvent); | 646 int event_mask = (1 << kInEvent); |
| 647 DartUtils::PostInt32(port, event_mask); | 647 DartUtils::PostInt32(handle->port(), event_mask); |
| 648 } else if (!handle->HasPendingRead() && | 648 } else if (!handle->HasPendingRead() && |
| 649 !handle->IsClosedRead()) { | 649 !handle->IsClosedRead()) { |
| 650 handle->IssueRead(); | 650 handle->IssueRead(); |
| 651 } | 651 } |
| 652 } | 652 } |
| 653 | 653 |
| 654 // If can send callback had been requested and there is no pending | 654 // If can send callback had been requested and there is no pending |
| 655 // send post it immediately. | 655 // send post it immediately. |
| 656 if ((msg->data & (1 << kOutEvent)) != 0) { | 656 if ((msg->data & (1 << kOutEvent)) != 0) { |
| 657 if (!handle->HasPendingWrite()) { | 657 if (!handle->HasPendingWrite()) { |
| 658 int event_mask = (1 << kOutEvent); | 658 int event_mask = (1 << kOutEvent); |
| 659 DartUtils::PostInt32(port, event_mask); | 659 DartUtils::PostInt32(handle->port(), event_mask); |
| 660 } | 660 } |
| 661 } | 661 } |
| 662 | 662 |
| 663 if (handle->is_client_socket()) { | 663 if (handle->is_client_socket()) { |
| 664 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle); | 664 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle); |
| 665 if ((msg->data & (1 << kShutdownReadCommand)) != 0) { | 665 if ((msg->data & (1 << kShutdownReadCommand)) != 0) { |
| 666 client_socket->Shutdown(SD_RECEIVE); | 666 client_socket->Shutdown(SD_RECEIVE); |
| 667 } | 667 } |
| 668 | 668 |
| 669 if ((msg->data & (1 << kShutdownWriteCommand)) != 0) { | 669 if ((msg->data & (1 << kShutdownWriteCommand)) != 0) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 685 } | 685 } |
| 686 | 686 |
| 687 | 687 |
| 688 void EventHandlerImplementation::HandleAccept(ListenSocket* listen_socket, | 688 void EventHandlerImplementation::HandleAccept(ListenSocket* listen_socket, |
| 689 IOBuffer* buffer) { | 689 IOBuffer* buffer) { |
| 690 listen_socket->AcceptComplete(buffer, completion_port_); | 690 listen_socket->AcceptComplete(buffer, completion_port_); |
| 691 | 691 |
| 692 if (!listen_socket->IsClosing()) { | 692 if (!listen_socket->IsClosing()) { |
| 693 int event_mask = 1 << kInEvent; | 693 int event_mask = 1 << kInEvent; |
| 694 if ((listen_socket->mask() & event_mask) != 0) { | 694 if ((listen_socket->mask() & event_mask) != 0) { |
| 695 DartUtils::PostInt32(port, event_mask); | 695 DartUtils::PostInt32(listen_socket->port(), event_mask); |
| 696 } | 696 } |
| 697 } | 697 } |
| 698 | 698 |
| 699 if (listen_socket->IsClosed()) { | 699 if (listen_socket->IsClosed()) { |
| 700 delete listen_socket; | 700 delete listen_socket; |
| 701 } | 701 } |
| 702 } | 702 } |
| 703 | 703 |
| 704 | 704 |
| 705 void EventHandlerImplementation::HandleClosed(Handle* handle) { | 705 void EventHandlerImplementation::HandleClosed(Handle* handle) { |
| 706 if (!handle->IsClosing()) { | 706 if (!handle->IsClosing()) { |
| 707 int event_mask = 1 << kCloseEvent; | 707 int event_mask = 1 << kCloseEvent; |
| 708 DartUtils::PostInt32(port, event_mask); | 708 DartUtils::PostInt32(handle->port(), event_mask); |
| 709 } | 709 } |
| 710 } | 710 } |
| 711 | 711 |
| 712 | 712 |
| 713 void EventHandlerImplementation::HandleRead(Handle* handle, | 713 void EventHandlerImplementation::HandleRead(Handle* handle, |
| 714 int bytes, | 714 int bytes, |
| 715 IOBuffer* buffer) { | 715 IOBuffer* buffer) { |
| 716 buffer->set_data_length(bytes); | 716 buffer->set_data_length(bytes); |
| 717 handle->ReadComplete(buffer); | 717 handle->ReadComplete(buffer); |
| 718 if (bytes > 0) { | 718 if (bytes > 0) { |
| 719 if (!handle->IsClosing()) { | 719 if (!handle->IsClosing()) { |
| 720 int event_mask = 1 << kInEvent; | 720 int event_mask = 1 << kInEvent; |
| 721 if ((handle->mask() & event_mask) != 0) { | 721 if ((handle->mask() & event_mask) != 0) { |
| 722 DartUtils::PostInt32(port, event_mask); | 722 DartUtils::PostInt32(handle->port(), event_mask); |
| 723 } | 723 } |
| 724 } | 724 } |
| 725 } else { | 725 } else { |
| 726 ASSERT(bytes == 0); | 726 ASSERT(bytes == 0); |
| 727 handle->MarkClosedRead(); | 727 handle->MarkClosedRead(); |
| 728 HandleClosed(handle); | 728 HandleClosed(handle); |
| 729 } | 729 } |
| 730 | 730 |
| 731 if (handle->IsClosed()) { | 731 if (handle->IsClosed()) { |
| 732 delete handle; | 732 delete handle; |
| 733 } | 733 } |
| 734 } | 734 } |
| 735 | 735 |
| 736 | 736 |
| 737 void EventHandlerImplementation::HandleWrite(Handle* handle, | 737 void EventHandlerImplementation::HandleWrite(Handle* handle, |
| 738 int bytes, | 738 int bytes, |
| 739 IOBuffer* buffer) { | 739 IOBuffer* buffer) { |
| 740 handle->WriteComplete(buffer); | 740 handle->WriteComplete(buffer); |
| 741 | 741 |
| 742 if (bytes > 0) { | 742 if (bytes > 0) { |
| 743 if (!handle->IsClosing()) { | 743 if (!handle->IsClosing()) { |
| 744 int event_mask = 1 << kOutEvent; | 744 int event_mask = 1 << kOutEvent; |
| 745 if ((handle->mask() & event_mask) != 0) { | 745 if ((handle->mask() & event_mask) != 0) { |
| 746 DartUtils::PostInt32(port, event_mask); | 746 DartUtils::PostInt32(handle->port(), event_mask); |
| 747 } | 747 } |
| 748 } | 748 } |
| 749 } else { | 749 } else { |
| 750 ASSERT(bytes == 0); | 750 ASSERT(bytes == 0); |
| 751 HandleClosed(handle); | 751 HandleClosed(handle); |
| 752 } | 752 } |
| 753 | 753 |
| 754 if (handle->IsClosed()) { | 754 if (handle->IsClosed()) { |
| 755 delete handle; | 755 delete handle; |
| 756 } | 756 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 reinterpret_cast<uword>(this)); | 886 reinterpret_cast<uword>(this)); |
| 887 if (result != 0) { | 887 if (result != 0) { |
| 888 FATAL1("Failed to start event handler thread %d", result); | 888 FATAL1("Failed to start event handler thread %d", result); |
| 889 } | 889 } |
| 890 | 890 |
| 891 // Initialize Winsock32 | 891 // Initialize Winsock32 |
| 892 if (!Socket::Initialize()) { | 892 if (!Socket::Initialize()) { |
| 893 FATAL("Failed to initialized Windows sockets"); | 893 FATAL("Failed to initialized Windows sockets"); |
| 894 } | 894 } |
| 895 } | 895 } |
| OLD | NEW |