OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "bin/eventhandler.h" | 8 #include "bin/eventhandler.h" |
9 | 9 |
10 #include <winsock2.h> // NOLINT | 10 #include <winsock2.h> // NOLINT |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 | 1007 |
1008 void EventHandlerImplementation::HandleInterrupt(InterruptMessage* msg) { | 1008 void EventHandlerImplementation::HandleInterrupt(InterruptMessage* msg) { |
1009 ASSERT(this != NULL); | 1009 ASSERT(this != NULL); |
1010 if (msg->id == kTimerId) { | 1010 if (msg->id == kTimerId) { |
1011 // Change of timeout request. Just set the new timeout and port as the | 1011 // Change of timeout request. Just set the new timeout and port as the |
1012 // completion thread will use the new timeout value for its next wait. | 1012 // completion thread will use the new timeout value for its next wait. |
1013 timeout_queue_.UpdateTimeout(msg->dart_port, msg->data); | 1013 timeout_queue_.UpdateTimeout(msg->dart_port, msg->data); |
1014 } else if (msg->id == kShutdownId) { | 1014 } else if (msg->id == kShutdownId) { |
1015 shutdown_ = true; | 1015 shutdown_ = true; |
1016 } else { | 1016 } else { |
1017 // No tokens to return on Windows. | |
1018 if ((msg->data & (1 << kReturnTokenCommand)) != 0) return; | |
1019 Handle* handle = reinterpret_cast<Handle*>(msg->id); | 1017 Handle* handle = reinterpret_cast<Handle*>(msg->id); |
1020 ASSERT(handle != NULL); | 1018 ASSERT(handle != NULL); |
1021 if (handle->is_listen_socket()) { | 1019 if (handle->is_listen_socket()) { |
1022 ListenSocket* listen_socket = | 1020 ListenSocket* listen_socket = |
1023 reinterpret_cast<ListenSocket*>(handle); | 1021 reinterpret_cast<ListenSocket*>(handle); |
1024 listen_socket->EnsureInitialized(this); | 1022 listen_socket->EnsureInitialized(this); |
1025 listen_socket->SetPortAndMask(msg->dart_port, msg->data); | |
1026 | 1023 |
1027 Handle::ScopedLock lock(listen_socket); | 1024 Handle::ScopedLock lock(listen_socket); |
1028 | 1025 |
1029 // If incoming connections are requested make sure to post already | 1026 if (IS_COMMAND(msg->data, kReturnTokenCommand)) { |
1030 // accepted connections. | 1027 // No tokens to return on Windows. |
1031 if ((msg->data & (1 << kInEvent)) != 0) { | 1028 } else if (IS_COMMAND(msg->data, kSetEventMaskCommand)) { |
1032 if (listen_socket->CanAccept()) { | 1029 // `events` can only have kInEvent/kOutEvent flags set. |
1033 int event_mask = (1 << kInEvent); | 1030 intptr_t events = msg->data & EVENT_MASK; |
1034 handle->set_mask(handle->mask() & ~event_mask); | 1031 ASSERT(0 == (events & ~(1 << kInEvent | 1 << kOutEvent))); |
1035 DartUtils::PostInt32(handle->port(), event_mask); | 1032 |
| 1033 listen_socket->SetPortAndMask(msg->dart_port, msg->data); |
| 1034 |
| 1035 // If incoming connections are requested make sure to post already |
| 1036 // accepted connections. |
| 1037 if ((events & (1 << kInEvent)) != 0) { |
| 1038 if (listen_socket->CanAccept()) { |
| 1039 int event_mask = (1 << kInEvent); |
| 1040 handle->set_mask(handle->mask() & ~event_mask); |
| 1041 DartUtils::PostInt32(handle->port(), event_mask); |
| 1042 } |
1036 } | 1043 } |
| 1044 } else if (IS_COMMAND(msg->data, kCloseCommand)) { |
| 1045 handle->SetPortAndMask(msg->dart_port, msg->data); |
| 1046 handle->Close(); |
| 1047 } else { |
| 1048 UNREACHABLE(); |
1037 } | 1049 } |
1038 } else { | 1050 } else { |
1039 handle->EnsureInitialized(this); | 1051 handle->EnsureInitialized(this); |
1040 | 1052 |
1041 Handle::ScopedLock lock(handle); | 1053 Handle::ScopedLock lock(handle); |
1042 | 1054 |
1043 // Only set mask if we turned on kInEvent or kOutEvent. | 1055 if (IS_COMMAND(msg->data, kReturnTokenCommand)) { |
1044 if ((msg->data & ((1 << kInEvent) | (1 << kOutEvent))) != 0) { | 1056 // No tokens to return on Windows. |
| 1057 } else if (IS_COMMAND(msg->data, kSetEventMaskCommand)) { |
| 1058 // `events` can only have kInEvent/kOutEvent flags set. |
| 1059 intptr_t events = msg->data & EVENT_MASK; |
| 1060 ASSERT(0 == (events & ~(1 << kInEvent | 1 << kOutEvent))); |
| 1061 |
1045 handle->SetPortAndMask(msg->dart_port, msg->data); | 1062 handle->SetPortAndMask(msg->dart_port, msg->data); |
1046 } | |
1047 | 1063 |
1048 // Issue a read. | 1064 // Issue a read. |
1049 if ((msg->data & (1 << kInEvent)) != 0) { | 1065 if ((msg->data & (1 << kInEvent)) != 0) { |
1050 if (handle->is_datagram_socket()) { | 1066 if (handle->is_datagram_socket()) { |
1051 handle->IssueRecvFrom(); | 1067 handle->IssueRecvFrom(); |
1052 } else if (handle->is_client_socket()) { | 1068 } else if (handle->is_client_socket()) { |
1053 if (reinterpret_cast<ClientSocket*>(handle)->is_connected()) { | 1069 if (reinterpret_cast<ClientSocket*>(handle)->is_connected()) { |
| 1070 handle->IssueRead(); |
| 1071 } |
| 1072 } else { |
1054 handle->IssueRead(); | 1073 handle->IssueRead(); |
1055 } | 1074 } |
1056 } else { | |
1057 handle->IssueRead(); | |
1058 } | 1075 } |
1059 } | |
1060 | 1076 |
1061 // If out events (can write events) have been requested, and there | 1077 // If out events (can write events) have been requested, and there |
1062 // are no pending writes, meaning any writes are already complete, | 1078 // are no pending writes, meaning any writes are already complete, |
1063 // post an out event immediately. | 1079 // post an out event immediately. |
1064 if ((msg->data & (1 << kOutEvent)) != 0) { | 1080 if ((msg->data & (1 << kOutEvent)) != 0) { |
1065 if (!handle->HasPendingWrite()) { | 1081 if (!handle->HasPendingWrite()) { |
1066 if (handle->is_client_socket()) { | 1082 if (handle->is_client_socket()) { |
1067 if (reinterpret_cast<ClientSocket*>(handle)->is_connected()) { | 1083 if (reinterpret_cast<ClientSocket*>(handle)->is_connected()) { |
| 1084 DartUtils::PostInt32(handle->port(), 1 << kOutEvent); |
| 1085 } |
| 1086 } else { |
1068 DartUtils::PostInt32(handle->port(), 1 << kOutEvent); | 1087 DartUtils::PostInt32(handle->port(), 1 << kOutEvent); |
1069 } | 1088 } |
1070 } else { | |
1071 DartUtils::PostInt32(handle->port(), 1 << kOutEvent); | |
1072 } | 1089 } |
1073 } | 1090 } |
1074 } | 1091 } else if (IS_COMMAND(msg->data, kShutdownReadCommand)) { |
| 1092 ASSERT(handle->is_client_socket()); |
1075 | 1093 |
1076 if (handle->is_client_socket()) { | |
1077 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle); | 1094 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle); |
1078 if ((msg->data & (1 << kShutdownReadCommand)) != 0) { | 1095 if ((msg->data & (1 << kShutdownReadCommand)) != 0) { |
1079 client_socket->Shutdown(SD_RECEIVE); | 1096 client_socket->Shutdown(SD_RECEIVE); |
1080 } | 1097 } |
| 1098 } else if (IS_COMMAND(msg->data, kShutdownWriteCommand)) { |
| 1099 ASSERT(handle->is_client_socket()); |
1081 | 1100 |
| 1101 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle); |
1082 if ((msg->data & (1 << kShutdownWriteCommand)) != 0) { | 1102 if ((msg->data & (1 << kShutdownWriteCommand)) != 0) { |
1083 client_socket->Shutdown(SD_SEND); | 1103 client_socket->Shutdown(SD_SEND); |
1084 } | 1104 } |
| 1105 } else if (IS_COMMAND(msg->data, kCloseCommand)) { |
| 1106 handle->SetPortAndMask(msg->dart_port, msg->data); |
| 1107 handle->Close(); |
| 1108 } else { |
| 1109 UNREACHABLE(); |
1085 } | 1110 } |
1086 } | 1111 } |
1087 | 1112 |
1088 if ((msg->data & (1 << kCloseCommand)) != 0) { | |
1089 handle->SetPortAndMask(msg->dart_port, msg->data); | |
1090 handle->Close(); | |
1091 } | |
1092 | |
1093 DeleteIfClosed(handle); | 1113 DeleteIfClosed(handle); |
1094 } | 1114 } |
1095 } | 1115 } |
1096 | 1116 |
1097 | 1117 |
1098 void EventHandlerImplementation::HandleAccept(ListenSocket* listen_socket, | 1118 void EventHandlerImplementation::HandleAccept(ListenSocket* listen_socket, |
1099 OverlappedBuffer* buffer) { | 1119 OverlappedBuffer* buffer) { |
1100 listen_socket->AcceptComplete(buffer, completion_port_); | 1120 listen_socket->AcceptComplete(buffer, completion_port_); |
1101 | 1121 |
1102 if (!listen_socket->IsClosing()) { | 1122 if (!listen_socket->IsClosing()) { |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 | 1380 |
1361 | 1381 |
1362 void EventHandlerImplementation::Shutdown() { | 1382 void EventHandlerImplementation::Shutdown() { |
1363 SendData(kShutdownId, 0, 0); | 1383 SendData(kShutdownId, 0, 0); |
1364 } | 1384 } |
1365 | 1385 |
1366 } // namespace bin | 1386 } // namespace bin |
1367 } // namespace dart | 1387 } // namespace dart |
1368 | 1388 |
1369 #endif // defined(TARGET_OS_WINDOWS) | 1389 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |