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 "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
7 | 7 |
8 #include "bin/eventhandler.h" | 8 #include "bin/eventhandler.h" |
9 #include "bin/eventhandler_linux.h" | 9 #include "bin/eventhandler_linux.h" |
10 | 10 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 Dart_Port port = msg[i].dart_port; | 234 Dart_Port port = msg[i].dart_port; |
235 di->RemovePort(port); | 235 di->RemovePort(port); |
236 intptr_t new_mask = di->Mask(); | 236 intptr_t new_mask = di->Mask(); |
237 UpdateEpollInstance(old_mask, di); | 237 UpdateEpollInstance(old_mask, di); |
238 | 238 |
239 intptr_t fd = di->fd(); | 239 intptr_t fd = di->fd(); |
240 if (di->IsListeningSocket()) { | 240 if (di->IsListeningSocket()) { |
241 // We only close the socket file descriptor from the operating | 241 // We only close the socket file descriptor from the operating |
242 // system if there are no other dart socket objects which | 242 // system if there are no other dart socket objects which |
243 // are listening on the same (address, port) combination. | 243 // are listening on the same (address, port) combination. |
| 244 ListeningSocketRegistry *registry = |
| 245 ListeningSocketRegistry::Instance(); |
244 | 246 |
245 // TODO(dart:io): This assumes that all sockets listen before we | 247 MutexLocker locker(registry->mutex()); |
246 // close. | 248 |
247 // This needs to be synchronized with a global datastructure. | 249 if (registry->CloseSafe(fd)) { |
248 if (new_mask == 0) { | 250 ASSERT(new_mask == 0); |
249 socket_map_.Remove( | 251 socket_map_.Remove(GetHashmapKeyFromFd(fd), |
250 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 252 GetHashmapHashFromFd(fd)); |
251 di->Close(); | 253 di->Close(); |
252 delete di; | 254 delete di; |
253 } | 255 } |
254 } else { | 256 } else { |
255 ASSERT(new_mask == 0); | 257 ASSERT(new_mask == 0); |
256 socket_map_.Remove( | 258 socket_map_.Remove( |
257 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 259 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
258 di->Close(); | 260 di->Close(); |
259 delete di; | 261 delete di; |
260 } | 262 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 | 413 |
412 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 414 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
413 // The hashmap does not support keys with value 0. | 415 // The hashmap does not support keys with value 0. |
414 return dart::Utils::WordHash(fd + 1); | 416 return dart::Utils::WordHash(fd + 1); |
415 } | 417 } |
416 | 418 |
417 } // namespace bin | 419 } // namespace bin |
418 } // namespace dart | 420 } // namespace dart |
419 | 421 |
420 #endif // defined(TARGET_OS_LINUX) | 422 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |