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 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 if (!ok) { | 1288 if (!ok) { |
1289 FATAL("PostQueuedCompletionStatus failed"); | 1289 FATAL("PostQueuedCompletionStatus failed"); |
1290 } | 1290 } |
1291 } | 1291 } |
1292 | 1292 |
1293 | 1293 |
1294 void EventHandlerImplementation::EventHandlerEntry(uword args) { | 1294 void EventHandlerImplementation::EventHandlerEntry(uword args) { |
1295 EventHandler* handler = reinterpret_cast<EventHandler*>(args); | 1295 EventHandler* handler = reinterpret_cast<EventHandler*>(args); |
1296 EventHandlerImplementation* handler_impl = &handler->delegate_; | 1296 EventHandlerImplementation* handler_impl = &handler->delegate_; |
1297 ASSERT(handler_impl != NULL); | 1297 ASSERT(handler_impl != NULL); |
| 1298 |
1298 while (!handler_impl->shutdown_) { | 1299 while (!handler_impl->shutdown_) { |
1299 DWORD bytes; | 1300 DWORD bytes; |
1300 ULONG_PTR key; | 1301 ULONG_PTR key; |
1301 OVERLAPPED* overlapped; | 1302 OVERLAPPED* overlapped; |
1302 int64_t millis = handler_impl->GetTimeout(); | 1303 int64_t millis = handler_impl->GetTimeout(); |
1303 ASSERT(millis == kInfinityTimeout || millis >= 0); | 1304 ASSERT(millis == kInfinityTimeout || millis >= 0); |
1304 if (millis > kMaxInt32) millis = kMaxInt32; | 1305 if (millis > kMaxInt32) millis = kMaxInt32; |
1305 ASSERT(sizeof(int32_t) == sizeof(DWORD)); | 1306 ASSERT(sizeof(int32_t) == sizeof(DWORD)); |
1306 BOOL ok = GetQueuedCompletionStatus(handler_impl->completion_port(), | 1307 BOOL ok = GetQueuedCompletionStatus(handler_impl->completion_port(), |
1307 &bytes, | 1308 &bytes, |
(...skipping 29 matching lines...) Expand all Loading... |
1337 } | 1338 } |
1338 } else if (key == NULL) { | 1339 } else if (key == NULL) { |
1339 // A key of NULL signals an interrupt message. | 1340 // A key of NULL signals an interrupt message. |
1340 InterruptMessage* msg = reinterpret_cast<InterruptMessage*>(overlapped); | 1341 InterruptMessage* msg = reinterpret_cast<InterruptMessage*>(overlapped); |
1341 handler_impl->HandleInterrupt(msg); | 1342 handler_impl->HandleInterrupt(msg); |
1342 delete msg; | 1343 delete msg; |
1343 } else { | 1344 } else { |
1344 handler_impl->HandleIOCompletion(bytes, key, overlapped); | 1345 handler_impl->HandleIOCompletion(bytes, key, overlapped); |
1345 } | 1346 } |
1346 } | 1347 } |
1347 delete handler; | 1348 handler->NotifyShutdownDone(); |
1348 } | 1349 } |
1349 | 1350 |
1350 | 1351 |
1351 void EventHandlerImplementation::Start(EventHandler* handler) { | 1352 void EventHandlerImplementation::Start(EventHandler* handler) { |
1352 int result = Thread::Start(EventHandlerEntry, | 1353 int result = Thread::Start(EventHandlerEntry, |
1353 reinterpret_cast<uword>(handler)); | 1354 reinterpret_cast<uword>(handler)); |
1354 if (result != 0) { | 1355 if (result != 0) { |
1355 FATAL1("Failed to start event handler thread %d", result); | 1356 FATAL1("Failed to start event handler thread %d", result); |
1356 } | 1357 } |
1357 | 1358 |
1358 // Initialize Winsock32 | 1359 // Initialize Winsock32 |
1359 if (!Socket::Initialize()) { | 1360 if (!Socket::Initialize()) { |
1360 FATAL("Failed to initialized Windows sockets"); | 1361 FATAL("Failed to initialized Windows sockets"); |
1361 } | 1362 } |
1362 } | 1363 } |
1363 | 1364 |
1364 | 1365 |
1365 void EventHandlerImplementation::Shutdown() { | 1366 void EventHandlerImplementation::Shutdown() { |
1366 SendData(kShutdownId, 0, 0); | 1367 SendData(kShutdownId, 0, 0); |
1367 } | 1368 } |
1368 | 1369 |
1369 } // namespace bin | 1370 } // namespace bin |
1370 } // namespace dart | 1371 } // namespace dart |
1371 | 1372 |
1372 #endif // defined(TARGET_OS_WINDOWS) | 1373 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |