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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
6 | 6 |
7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
8 #if defined(HOST_OS_WINDOWS) | 8 #if defined(HOST_OS_WINDOWS) |
9 | 9 |
10 #include "bin/eventhandler.h" | 10 #include "bin/eventhandler.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 data_length_ = num_bytes; | 108 data_length_ = num_bytes; |
109 return num_bytes; | 109 return num_bytes; |
110 } | 110 } |
111 | 111 |
112 | 112 |
113 int OverlappedBuffer::GetRemainingLength() { | 113 int OverlappedBuffer::GetRemainingLength() { |
114 ASSERT(operation_ == kRead || operation_ == kRecvFrom); | 114 ASSERT(operation_ == kRead || operation_ == kRecvFrom); |
115 return data_length_ - index_; | 115 return data_length_ - index_; |
116 } | 116 } |
117 | 117 |
118 | |
118 Handle::Handle(intptr_t handle) | 119 Handle::Handle(intptr_t handle) |
119 : DescriptorInfoBase(handle), | 120 : ReferenceCounted(), |
121 DescriptorInfoBase(handle), | |
120 handle_(reinterpret_cast<HANDLE>(handle)), | 122 handle_(reinterpret_cast<HANDLE>(handle)), |
121 completion_port_(INVALID_HANDLE_VALUE), | 123 completion_port_(INVALID_HANDLE_VALUE), |
122 event_handler_(NULL), | 124 event_handler_(NULL), |
123 data_ready_(NULL), | 125 data_ready_(NULL), |
124 pending_read_(NULL), | 126 pending_read_(NULL), |
125 pending_write_(NULL), | 127 pending_write_(NULL), |
126 last_error_(NOERROR), | 128 last_error_(NOERROR), |
127 flags_(0), | 129 flags_(0), |
128 read_thread_id_(Thread::kInvalidThreadId), | 130 read_thread_id_(Thread::kInvalidThreadId), |
129 read_thread_handle_(NULL), | 131 read_thread_handle_(NULL), |
130 read_thread_starting_(false), | 132 read_thread_starting_(false), |
131 read_thread_finished_(false), | 133 read_thread_finished_(false), |
132 monitor_(new Monitor()) {} | 134 monitor_(new Monitor()) {} |
133 | 135 |
134 | 136 |
135 Handle::~Handle() { | 137 Handle::~Handle() { |
136 delete monitor_; | 138 delete monitor_; |
137 } | 139 } |
138 | 140 |
139 | 141 |
140 bool Handle::CreateCompletionPort(HANDLE completion_port) { | 142 bool Handle::CreateCompletionPort(HANDLE completion_port) { |
143 ASSERT(completion_port_ == INVALID_HANDLE_VALUE); | |
144 Retain(); | |
zra
2017/03/25 22:39:50
// A reference to the Handle is Retained by the IO
| |
141 completion_port_ = CreateIoCompletionPort( | 145 completion_port_ = CreateIoCompletionPort( |
142 handle(), completion_port, reinterpret_cast<ULONG_PTR>(this), 0); | 146 handle(), completion_port, reinterpret_cast<ULONG_PTR>(this), 0); |
143 return (completion_port_ != NULL); | 147 return (completion_port_ != NULL); |
144 } | 148 } |
145 | 149 |
146 | 150 |
147 void Handle::Close() { | 151 void Handle::Close() { |
148 MonitorLocker ml(monitor_); | 152 MonitorLocker ml(monitor_); |
149 if (!SupportsOverlappedIO()) { | 153 if (!SupportsOverlappedIO()) { |
150 // If the handle uses synchronous I/O (e.g. stdin), cancel any pending | 154 // If the handle uses synchronous I/O (e.g. stdin), cancel any pending |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 } else { | 389 } else { |
386 HandleError(this); | 390 HandleError(this); |
387 } | 391 } |
388 SetLastError(error); | 392 SetLastError(error); |
389 } | 393 } |
390 | 394 |
391 | 395 |
392 void FileHandle::EnsureInitialized(EventHandlerImplementation* event_handler) { | 396 void FileHandle::EnsureInitialized(EventHandlerImplementation* event_handler) { |
393 MonitorLocker ml(monitor_); | 397 MonitorLocker ml(monitor_); |
394 event_handler_ = event_handler; | 398 event_handler_ = event_handler; |
395 if (SupportsOverlappedIO() && (completion_port_ == INVALID_HANDLE_VALUE)) { | 399 if (completion_port_ == INVALID_HANDLE_VALUE) { |
396 CreateCompletionPort(event_handler_->completion_port()); | 400 if (SupportsOverlappedIO()) { |
401 CreateCompletionPort(event_handler_->completion_port()); | |
402 } else { | |
403 // We need to retain the Handle even if overlapped IO is not supported. | |
404 Retain(); | |
zra
2017/03/25 22:39:50
// It is Released by DeleteIfClosed after ReadSync
| |
405 completion_port_ = event_handler_->completion_port(); | |
406 } | |
397 } | 407 } |
398 } | 408 } |
399 | 409 |
400 | 410 |
401 bool FileHandle::IsClosed() { | 411 bool FileHandle::IsClosed() { |
402 return IsClosing() && !HasPendingRead() && !HasPendingWrite(); | 412 return IsClosing() && !HasPendingRead() && !HasPendingWrite(); |
403 } | 413 } |
404 | 414 |
405 | 415 |
406 void DirectoryWatchHandle::EnsureInitialized( | 416 void DirectoryWatchHandle::EnsureInitialized( |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 closesocket(buffer->client()); | 549 closesocket(buffer->client()); |
540 } | 550 } |
541 | 551 |
542 pending_accept_count_--; | 552 pending_accept_count_--; |
543 OverlappedBuffer::DisposeBuffer(buffer); | 553 OverlappedBuffer::DisposeBuffer(buffer); |
544 } | 554 } |
545 | 555 |
546 | 556 |
547 static void DeleteIfClosed(Handle* handle) { | 557 static void DeleteIfClosed(Handle* handle) { |
548 if (handle->IsClosed()) { | 558 if (handle->IsClosed()) { |
559 handle->set_completion_port(INVALID_HANDLE_VALUE); | |
560 handle->set_event_handler(NULL); | |
549 handle->NotifyAllDartPorts(1 << kDestroyedEvent); | 561 handle->NotifyAllDartPorts(1 << kDestroyedEvent); |
550 handle->RemoveAllPorts(); | 562 handle->RemoveAllPorts(); |
551 delete handle; | 563 handle->Release(); |
zra
2017/03/25 22:39:50
// Once the Handle is closed, no further events on
| |
552 } | 564 } |
553 } | 565 } |
554 | 566 |
555 | 567 |
556 void ListenSocket::DoClose() { | 568 void ListenSocket::DoClose() { |
557 closesocket(socket()); | 569 closesocket(socket()); |
558 handle_ = INVALID_HANDLE_VALUE; | 570 handle_ = INVALID_HANDLE_VALUE; |
559 while (CanAccept()) { | 571 while (CanAccept()) { |
560 // Get rid of connections already accepted. | 572 // Get rid of connections already accepted. |
561 ClientSocket* client = Accept(); | 573 ClientSocket* client = Accept(); |
562 if (client != NULL) { | 574 if (client != NULL) { |
563 client->Close(); | 575 client->Close(); |
576 // Release the reference from the list. | |
zra
2017/03/25 22:39:50
// When an accept completes, we make a new ClientS
| |
577 client->Release(); | |
564 DeleteIfClosed(client); | 578 DeleteIfClosed(client); |
565 } else { | 579 } else { |
566 break; | 580 break; |
567 } | 581 } |
568 } | 582 } |
583 AcceptEx_ = NULL; | |
569 } | 584 } |
570 | 585 |
571 | 586 |
572 bool ListenSocket::CanAccept() { | 587 bool ListenSocket::CanAccept() { |
573 MonitorLocker ml(monitor_); | 588 MonitorLocker ml(monitor_); |
574 return accepted_head_ != NULL; | 589 return accepted_head_ != NULL; |
575 } | 590 } |
576 | 591 |
577 | 592 |
578 ClientSocket* ListenSocket::Accept() { | 593 ClientSocket* ListenSocket::Accept() { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 // Note that we return '0', unless a thread have already completed a write. | 800 // Note that we return '0', unless a thread have already completed a write. |
786 if (thread_wrote_ > 0) { | 801 if (thread_wrote_ > 0) { |
787 if (num_bytes > thread_wrote_) { | 802 if (num_bytes > thread_wrote_) { |
788 num_bytes = thread_wrote_; | 803 num_bytes = thread_wrote_; |
789 } | 804 } |
790 thread_wrote_ -= num_bytes; | 805 thread_wrote_ -= num_bytes; |
791 return num_bytes; | 806 return num_bytes; |
792 } | 807 } |
793 if (!write_thread_exists_) { | 808 if (!write_thread_exists_) { |
794 write_thread_exists_ = true; | 809 write_thread_exists_ = true; |
810 Retain(); | |
zra
2017/03/25 22:39:50
// The write thread gets a reference to the Handle
| |
795 int result = Thread::Start(WriteFileThread, reinterpret_cast<uword>(this)); | 811 int result = Thread::Start(WriteFileThread, reinterpret_cast<uword>(this)); |
796 if (result != 0) { | 812 if (result != 0) { |
797 FATAL1("Failed to start write file thread %d", result); | 813 FATAL1("Failed to start write file thread %d", result); |
798 } | 814 } |
799 while (!write_thread_running_) { | 815 while (!write_thread_running_) { |
800 // Wait until we the thread is running. | 816 // Wait until we the thread is running. |
801 ml.Wait(Monitor::kNoTimeout); | 817 ml.Wait(Monitor::kNoTimeout); |
802 } | 818 } |
803 } | 819 } |
804 // Only queue up to INT_MAX bytes. | 820 // Only queue up to INT_MAX bytes. |
(...skipping 16 matching lines...) Expand all Loading... | |
821 } | 837 } |
822 // Join the thread. | 838 // Join the thread. |
823 DWORD res = WaitForSingleObject(thread_handle_, INFINITE); | 839 DWORD res = WaitForSingleObject(thread_handle_, INFINITE); |
824 CloseHandle(thread_handle_); | 840 CloseHandle(thread_handle_); |
825 ASSERT(res == WAIT_OBJECT_0); | 841 ASSERT(res == WAIT_OBJECT_0); |
826 } | 842 } |
827 Handle::DoClose(); | 843 Handle::DoClose(); |
828 } | 844 } |
829 | 845 |
830 | 846 |
847 #if defined(DEBUG) | |
848 intptr_t ClientSocket::disconnecting_ = 0; | |
849 #endif | |
850 | |
851 | |
831 bool ClientSocket::LoadDisconnectEx() { | 852 bool ClientSocket::LoadDisconnectEx() { |
832 // Load the DisconnectEx function into memory using WSAIoctl. | 853 // Load the DisconnectEx function into memory using WSAIoctl. |
833 GUID guid_disconnect_ex = WSAID_DISCONNECTEX; | 854 GUID guid_disconnect_ex = WSAID_DISCONNECTEX; |
834 DWORD bytes; | 855 DWORD bytes; |
835 int status = | 856 int status = |
836 WSAIoctl(socket(), SIO_GET_EXTENSION_FUNCTION_POINTER, | 857 WSAIoctl(socket(), SIO_GET_EXTENSION_FUNCTION_POINTER, |
837 &guid_disconnect_ex, sizeof(guid_disconnect_ex), &DisconnectEx_, | 858 &guid_disconnect_ex, sizeof(guid_disconnect_ex), &DisconnectEx_, |
838 sizeof(DisconnectEx_), &bytes, NULL, NULL); | 859 sizeof(DisconnectEx_), &bytes, NULL, NULL); |
839 return (status != SOCKET_ERROR); | 860 return (status != SOCKET_ERROR); |
840 } | 861 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
907 | 928 |
908 void ClientSocket::IssueDisconnect() { | 929 void ClientSocket::IssueDisconnect() { |
909 OverlappedBuffer* buffer = OverlappedBuffer::AllocateDisconnectBuffer(); | 930 OverlappedBuffer* buffer = OverlappedBuffer::AllocateDisconnectBuffer(); |
910 BOOL ok = | 931 BOOL ok = |
911 DisconnectEx_(socket(), buffer->GetCleanOverlapped(), TF_REUSE_SOCKET, 0); | 932 DisconnectEx_(socket(), buffer->GetCleanOverlapped(), TF_REUSE_SOCKET, 0); |
912 // DisconnectEx works like other OverlappedIO APIs, where we can get either an | 933 // DisconnectEx works like other OverlappedIO APIs, where we can get either an |
913 // immediate success or delayed operation by WSA_IO_PENDING being set. | 934 // immediate success or delayed operation by WSA_IO_PENDING being set. |
914 if (ok || (WSAGetLastError() != WSA_IO_PENDING)) { | 935 if (ok || (WSAGetLastError() != WSA_IO_PENDING)) { |
915 DisconnectComplete(buffer); | 936 DisconnectComplete(buffer); |
916 } | 937 } |
938 // When the Dart side receives this event, it may decide to close its Dart | |
939 // ports. When all ports are closed, the VM will shut down. The EventHandler | |
940 // will then shut down. If the EventHandler shuts down before this | |
941 // asynchronous disconnect finishes, this ClientSocket will be leaked. | |
942 // TODO(dart:io): Retain a list of client sockets that are in the process of | |
943 // disconnecting. Disconnect them forcefully, and clean up their resources | |
944 // when the EventHandler shuts down. | |
917 NotifyAllDartPorts(1 << kDestroyedEvent); | 945 NotifyAllDartPorts(1 << kDestroyedEvent); |
918 RemoveAllPorts(); | 946 RemoveAllPorts(); |
947 #if defined(DEBUG) | |
948 disconnecting_++; | |
949 #endif | |
919 } | 950 } |
920 | 951 |
921 | 952 |
922 void ClientSocket::DisconnectComplete(OverlappedBuffer* buffer) { | 953 void ClientSocket::DisconnectComplete(OverlappedBuffer* buffer) { |
923 OverlappedBuffer::DisposeBuffer(buffer); | 954 OverlappedBuffer::DisposeBuffer(buffer); |
924 closesocket(socket()); | 955 closesocket(socket()); |
925 if (data_ready_ != NULL) { | 956 if (data_ready_ != NULL) { |
926 OverlappedBuffer::DisposeBuffer(data_ready_); | 957 OverlappedBuffer::DisposeBuffer(data_ready_); |
927 } | 958 } |
928 mark_closed(); | 959 mark_closed(); |
960 #if defined(DEBUG) | |
961 disconnecting_--; | |
962 #endif | |
929 } | 963 } |
930 | 964 |
931 | 965 |
932 void ClientSocket::ConnectComplete(OverlappedBuffer* buffer) { | 966 void ClientSocket::ConnectComplete(OverlappedBuffer* buffer) { |
933 OverlappedBuffer::DisposeBuffer(buffer); | 967 OverlappedBuffer::DisposeBuffer(buffer); |
934 // Update socket to support full socket API, after ConnectEx completed. | 968 // Update socket to support full socket API, after ConnectEx completed. |
935 setsockopt(socket(), SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0); | 969 setsockopt(socket(), SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0); |
936 // If the port is set, we already listen for this socket in Dart. | 970 // If the port is set, we already listen for this socket in Dart. |
937 // Handle the cases here. | 971 // Handle the cases here. |
938 if (!IsClosedRead() && ((Mask() & (1 << kInEvent)) != 0)) { | 972 if (!IsClosedRead() && ((Mask() & (1 << kInEvent)) != 0)) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1030 | 1064 |
1031 void EventHandlerImplementation::HandleInterrupt(InterruptMessage* msg) { | 1065 void EventHandlerImplementation::HandleInterrupt(InterruptMessage* msg) { |
1032 ASSERT(this != NULL); | 1066 ASSERT(this != NULL); |
1033 if (msg->id == kTimerId) { | 1067 if (msg->id == kTimerId) { |
1034 // Change of timeout request. Just set the new timeout and port as the | 1068 // Change of timeout request. Just set the new timeout and port as the |
1035 // completion thread will use the new timeout value for its next wait. | 1069 // completion thread will use the new timeout value for its next wait. |
1036 timeout_queue_.UpdateTimeout(msg->dart_port, msg->data); | 1070 timeout_queue_.UpdateTimeout(msg->dart_port, msg->data); |
1037 } else if (msg->id == kShutdownId) { | 1071 } else if (msg->id == kShutdownId) { |
1038 shutdown_ = true; | 1072 shutdown_ = true; |
1039 } else { | 1073 } else { |
1040 Handle* handle = reinterpret_cast<Handle*>(msg->id); | 1074 Socket* socket = reinterpret_cast<Socket*>(msg->id); |
1075 RefCntReleaseScope<Socket> rs(socket); | |
1076 if (socket->fd() == -1) { | |
1077 return; | |
1078 } | |
1079 Handle* handle = reinterpret_cast<Handle*>(socket->fd()); | |
1041 ASSERT(handle != NULL); | 1080 ASSERT(handle != NULL); |
1042 | 1081 |
1043 if (handle->is_listen_socket()) { | 1082 if (handle->is_listen_socket()) { |
1044 ListenSocket* listen_socket = reinterpret_cast<ListenSocket*>(handle); | 1083 ListenSocket* listen_socket = reinterpret_cast<ListenSocket*>(handle); |
1045 listen_socket->EnsureInitialized(this); | 1084 listen_socket->EnsureInitialized(this); |
1046 | 1085 |
1047 MonitorLocker ml(listen_socket->monitor_); | 1086 MonitorLocker ml(listen_socket->monitor_); |
1048 | 1087 |
1049 if (IS_COMMAND(msg->data, kReturnTokenCommand)) { | 1088 if (IS_COMMAND(msg->data, kReturnTokenCommand)) { |
1050 listen_socket->ReturnTokens(msg->dart_port, TOKEN_COUNT(msg->data)); | 1089 listen_socket->ReturnTokens(msg->dart_port, TOKEN_COUNT(msg->data)); |
1051 } else if (IS_COMMAND(msg->data, kSetEventMaskCommand)) { | 1090 } else if (IS_COMMAND(msg->data, kSetEventMaskCommand)) { |
1052 // `events` can only have kInEvent/kOutEvent flags set. | 1091 // `events` can only have kInEvent/kOutEvent flags set. |
1053 intptr_t events = msg->data & EVENT_MASK; | 1092 intptr_t events = msg->data & EVENT_MASK; |
1054 ASSERT(0 == (events & ~(1 << kInEvent | 1 << kOutEvent))); | 1093 ASSERT(0 == (events & ~(1 << kInEvent | 1 << kOutEvent))); |
1055 listen_socket->SetPortAndMask(msg->dart_port, events); | 1094 listen_socket->SetPortAndMask(msg->dart_port, events); |
1056 TryDispatchingPendingAccepts(listen_socket); | 1095 TryDispatchingPendingAccepts(listen_socket); |
1057 } else if (IS_COMMAND(msg->data, kCloseCommand)) { | 1096 } else if (IS_COMMAND(msg->data, kCloseCommand)) { |
1058 listen_socket->RemovePort(msg->dart_port); | 1097 listen_socket->RemovePort(msg->dart_port); |
1059 | 1098 |
1060 // We only close the socket file descriptor from the operating | 1099 // We only close the socket file descriptor from the operating |
1061 // system if there are no other dart socket objects which | 1100 // system if there are no other dart socket objects which |
1062 // are listening on the same (address, port) combination. | 1101 // are listening on the same (address, port) combination. |
1063 ListeningSocketRegistry* registry = ListeningSocketRegistry::Instance(); | 1102 ListeningSocketRegistry* registry = ListeningSocketRegistry::Instance(); |
1064 MutexLocker locker(registry->mutex()); | 1103 MutexLocker locker(registry->mutex()); |
1065 if (registry->CloseSafe(reinterpret_cast<intptr_t>(listen_socket))) { | 1104 if (registry->CloseSafe(socket)) { |
1066 ASSERT(listen_socket->Mask() == 0); | 1105 ASSERT(listen_socket->Mask() == 0); |
1067 listen_socket->Close(); | 1106 listen_socket->Close(); |
1107 socket->SetClosedFd(); | |
1068 } | 1108 } |
1069 | 1109 |
1070 DartUtils::PostInt32(msg->dart_port, 1 << kDestroyedEvent); | 1110 DartUtils::PostInt32(msg->dart_port, 1 << kDestroyedEvent); |
1071 } else { | 1111 } else { |
1072 UNREACHABLE(); | 1112 UNREACHABLE(); |
1073 } | 1113 } |
1074 } else { | 1114 } else { |
1075 handle->EnsureInitialized(this); | 1115 handle->EnsureInitialized(this); |
1076 MonitorLocker ml(handle->monitor_); | 1116 MonitorLocker ml(handle->monitor_); |
1077 | 1117 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1125 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle); | 1165 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle); |
1126 client_socket->Shutdown(SD_RECEIVE); | 1166 client_socket->Shutdown(SD_RECEIVE); |
1127 } else if (IS_COMMAND(msg->data, kShutdownWriteCommand)) { | 1167 } else if (IS_COMMAND(msg->data, kShutdownWriteCommand)) { |
1128 ASSERT(handle->is_client_socket()); | 1168 ASSERT(handle->is_client_socket()); |
1129 | 1169 |
1130 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle); | 1170 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle); |
1131 client_socket->Shutdown(SD_SEND); | 1171 client_socket->Shutdown(SD_SEND); |
1132 } else if (IS_COMMAND(msg->data, kCloseCommand)) { | 1172 } else if (IS_COMMAND(msg->data, kCloseCommand)) { |
1133 handle->SetPortAndMask(msg->dart_port, 0); | 1173 handle->SetPortAndMask(msg->dart_port, 0); |
1134 handle->Close(); | 1174 handle->Close(); |
1175 socket->SetClosedFd(); | |
1135 } else { | 1176 } else { |
1136 UNREACHABLE(); | 1177 UNREACHABLE(); |
1137 } | 1178 } |
1138 } | 1179 } |
1139 | 1180 |
1140 DeleteIfClosed(handle); | 1181 DeleteIfClosed(handle); |
1141 } | 1182 } |
1142 } | 1183 } |
1143 | 1184 |
1144 | 1185 |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1421 } | 1462 } |
1422 } else if (key == NULL) { | 1463 } else if (key == NULL) { |
1423 // A key of NULL signals an interrupt message. | 1464 // A key of NULL signals an interrupt message. |
1424 InterruptMessage* msg = reinterpret_cast<InterruptMessage*>(overlapped); | 1465 InterruptMessage* msg = reinterpret_cast<InterruptMessage*>(overlapped); |
1425 handler_impl->HandleInterrupt(msg); | 1466 handler_impl->HandleInterrupt(msg); |
1426 delete msg; | 1467 delete msg; |
1427 } else { | 1468 } else { |
1428 handler_impl->HandleIOCompletion(bytes, key, overlapped); | 1469 handler_impl->HandleIOCompletion(bytes, key, overlapped); |
1429 } | 1470 } |
1430 } | 1471 } |
1472 | |
1473 // The eventhandler thread is going down so there should be no more live | |
1474 // Handles or Sockets. | |
1475 // TODO(dart:io): It would be nice to be able to assert here that: | |
1476 // ReferenceCounted<Handle>::instances() == 0; | |
1477 // However, we cannot at the moment. See the TODO on: | |
1478 // ClientSocket::IssueDisconnect() | |
1479 DEBUG_ASSERT(ReferenceCounted<Handle>::instances() == | |
1480 ClientSocket::disconnecting()); | |
1481 DEBUG_ASSERT(ReferenceCounted<Socket>::instances() == 0); | |
1431 handler->NotifyShutdownDone(); | 1482 handler->NotifyShutdownDone(); |
1432 } | 1483 } |
1433 | 1484 |
1434 | 1485 |
1435 void EventHandlerImplementation::Start(EventHandler* handler) { | 1486 void EventHandlerImplementation::Start(EventHandler* handler) { |
1436 int result = | 1487 int result = |
1437 Thread::Start(EventHandlerEntry, reinterpret_cast<uword>(handler)); | 1488 Thread::Start(EventHandlerEntry, reinterpret_cast<uword>(handler)); |
1438 if (result != 0) { | 1489 if (result != 0) { |
1439 FATAL1("Failed to start event handler thread %d", result); | 1490 FATAL1("Failed to start event handler thread %d", result); |
1440 } | 1491 } |
(...skipping 15 matching lines...) Expand all Loading... | |
1456 void EventHandlerImplementation::Shutdown() { | 1507 void EventHandlerImplementation::Shutdown() { |
1457 SendData(kShutdownId, 0, 0); | 1508 SendData(kShutdownId, 0, 0); |
1458 } | 1509 } |
1459 | 1510 |
1460 } // namespace bin | 1511 } // namespace bin |
1461 } // namespace dart | 1512 } // namespace dart |
1462 | 1513 |
1463 #endif // defined(HOST_OS_WINDOWS) | 1514 #endif // defined(HOST_OS_WINDOWS) |
1464 | 1515 |
1465 #endif // !defined(DART_IO_DISABLED) | 1516 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |