Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: dart/runtime/bin/eventhandler_win.cc

Issue 913753002: Reland "Introduce optional 'bool shared' parameter to ServerSocket.bind() ..." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "bin/eventhandler_win.h" 9 #include "bin/eventhandler_win.h"
10 10
(...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 1011
1012 if (IS_COMMAND(msg->data, kReturnTokenCommand)) { 1012 if (IS_COMMAND(msg->data, kReturnTokenCommand)) {
1013 listen_socket->ReturnTokens(msg->dart_port, TOKEN_COUNT(msg->data)); 1013 listen_socket->ReturnTokens(msg->dart_port, TOKEN_COUNT(msg->data));
1014 } else if (IS_COMMAND(msg->data, kSetEventMaskCommand)) { 1014 } else if (IS_COMMAND(msg->data, kSetEventMaskCommand)) {
1015 // `events` can only have kInEvent/kOutEvent flags set. 1015 // `events` can only have kInEvent/kOutEvent flags set.
1016 intptr_t events = msg->data & EVENT_MASK; 1016 intptr_t events = msg->data & EVENT_MASK;
1017 ASSERT(0 == (events & ~(1 << kInEvent | 1 << kOutEvent))); 1017 ASSERT(0 == (events & ~(1 << kInEvent | 1 << kOutEvent)));
1018 listen_socket->SetPortAndMask(msg->dart_port, events); 1018 listen_socket->SetPortAndMask(msg->dart_port, events);
1019 TryDispatchingPendingAccepts(listen_socket); 1019 TryDispatchingPendingAccepts(listen_socket);
1020 } else if (IS_COMMAND(msg->data, kCloseCommand)) { 1020 } else if (IS_COMMAND(msg->data, kCloseCommand)) {
1021 handle->SetPortAndMask(msg->dart_port, 0); 1021 listen_socket->SetPortAndMask(msg->dart_port, 0);
1022 if (handle->Mask() == 0) { 1022 // We only close the socket file descriptor from the operating
1023 // TODO(dart:io): This assumes that all sockets listen before we 1023 // system if there are no other dart socket objects which
1024 // close. 1024 // are listening on the same (address, port) combination.
1025 // This needs to be synchronized with a global datastructure. 1025 ListeningSocketRegistry *registry =
1026 handle->Close(); 1026 ListeningSocketRegistry::Instance();
1027 MutexLocker locker(registry->mutex());
1028 if (registry->CloseSafe(reinterpret_cast<intptr_t>(listen_socket))) {
1029 ASSERT(listen_socket->Mask() == 0);
1030 listen_socket->Close();
kustermann 2015/02/10 16:35:51 Note that the `Handle::ScopedLock lock()` from abo
Søren Gjesse 2015/02/11 08:51:05 It uses a Windows critical section object which is
1031 DeleteIfClosed(handle);
1027 } 1032 }
1028 } else { 1033 } else {
1029 UNREACHABLE(); 1034 UNREACHABLE();
1030 } 1035 }
1031 } else { 1036 } else {
1032 handle->EnsureInitialized(this); 1037 handle->EnsureInitialized(this);
1033 1038
1034 Handle::ScopedLock lock(handle); 1039 Handle::ScopedLock lock(handle);
1035 1040
1036 if (IS_COMMAND(msg->data, kReturnTokenCommand)) { 1041 if (IS_COMMAND(msg->data, kReturnTokenCommand)) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 ASSERT(handle->is_client_socket()); 1091 ASSERT(handle->is_client_socket());
1087 1092
1088 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle); 1093 ClientSocket* client_socket = reinterpret_cast<ClientSocket*>(handle);
1089 client_socket->Shutdown(SD_SEND); 1094 client_socket->Shutdown(SD_SEND);
1090 } else if (IS_COMMAND(msg->data, kCloseCommand)) { 1095 } else if (IS_COMMAND(msg->data, kCloseCommand)) {
1091 handle->SetPortAndMask(msg->dart_port, 0); 1096 handle->SetPortAndMask(msg->dart_port, 0);
1092 handle->Close(); 1097 handle->Close();
1093 } else { 1098 } else {
1094 UNREACHABLE(); 1099 UNREACHABLE();
1095 } 1100 }
1101 DeleteIfClosed(handle);
1096 } 1102 }
1097 DeleteIfClosed(handle);
1098 } 1103 }
1099 } 1104 }
1100 1105
1101 1106
1102 void EventHandlerImplementation::HandleAccept(ListenSocket* listen_socket, 1107 void EventHandlerImplementation::HandleAccept(ListenSocket* listen_socket,
1103 OverlappedBuffer* buffer) { 1108 OverlappedBuffer* buffer) {
1104 listen_socket->AcceptComplete(buffer, completion_port_); 1109 listen_socket->AcceptComplete(buffer, completion_port_);
1105 1110
1106 { 1111 {
1107 Handle::ScopedLock lock(listen_socket); 1112 Handle::ScopedLock lock(listen_socket);
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 1385
1381 1386
1382 void EventHandlerImplementation::Shutdown() { 1387 void EventHandlerImplementation::Shutdown() {
1383 SendData(kShutdownId, 0, 0); 1388 SendData(kShutdownId, 0, 0);
1384 } 1389 }
1385 1390
1386 } // namespace bin 1391 } // namespace bin
1387 } // namespace dart 1392 } // namespace dart
1388 1393
1389 #endif // defined(TARGET_OS_WINDOWS) 1394 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698