| 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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 7 | 7 |
| 8 #include "bin/eventhandler.h" | 8 #include "bin/eventhandler.h" |
| 9 #include "bin/eventhandler_android.h" | 9 #include "bin/eventhandler_android.h" |
| 10 | 10 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 Dart_Port port = msg[i].dart_port; | 216 Dart_Port port = msg[i].dart_port; |
| 217 di->RemovePort(port); | 217 di->RemovePort(port); |
| 218 intptr_t new_mask = di->Mask(); | 218 intptr_t new_mask = di->Mask(); |
| 219 UpdateEpollInstance(old_mask, di); | 219 UpdateEpollInstance(old_mask, di); |
| 220 | 220 |
| 221 intptr_t fd = di->fd(); | 221 intptr_t fd = di->fd(); |
| 222 if (di->IsListeningSocket()) { | 222 if (di->IsListeningSocket()) { |
| 223 // We only close the socket file descriptor from the operating | 223 // We only close the socket file descriptor from the operating |
| 224 // system if there are no other dart socket objects which | 224 // system if there are no other dart socket objects which |
| 225 // are listening on the same (address, port) combination. | 225 // are listening on the same (address, port) combination. |
| 226 ListeningSocketRegistry *registry = |
| 227 ListeningSocketRegistry::Instance(); |
| 226 | 228 |
| 227 // TODO(dart:io): This assumes that all sockets listen before we | 229 MutexLocker locker(registry->mutex()); |
| 228 // close. | 230 |
| 229 // This needs to be synchronized with a global datastructure. | 231 if (registry->CloseSafe(fd)) { |
| 230 if (new_mask == 0) { | 232 ASSERT(new_mask == 0); |
| 231 socket_map_.Remove( | 233 socket_map_.Remove(GetHashmapKeyFromFd(fd), |
| 232 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 234 GetHashmapHashFromFd(fd)); |
| 233 di->Close(); | 235 di->Close(); |
| 234 delete di; | 236 delete di; |
| 235 } | 237 } |
| 236 } else { | 238 } else { |
| 237 ASSERT(new_mask == 0); | 239 ASSERT(new_mask == 0); |
| 238 socket_map_.Remove( | 240 socket_map_.Remove( |
| 239 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 241 GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
| 240 di->Close(); | 242 di->Close(); |
| 241 delete di; | 243 delete di; |
| 242 } | 244 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 407 |
| 406 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { | 408 uint32_t EventHandlerImplementation::GetHashmapHashFromFd(intptr_t fd) { |
| 407 // The hashmap does not support keys with value 0. | 409 // The hashmap does not support keys with value 0. |
| 408 return dart::Utils::WordHash(fd + 1); | 410 return dart::Utils::WordHash(fd + 1); |
| 409 } | 411 } |
| 410 | 412 |
| 411 } // namespace bin | 413 } // namespace bin |
| 412 } // namespace dart | 414 } // namespace dart |
| 413 | 415 |
| 414 #endif // defined(TARGET_OS_ANDROID) | 416 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |