OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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_FUCHSIA) | 8 #if defined(HOST_OS_FUCHSIA) |
9 | 9 |
10 #include "bin/eventhandler.h" | 10 #include "bin/eventhandler.h" |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) { | 272 for (ssize_t i = 0; i < bytes / kInterruptMessageSize; i++) { |
273 if (msg[i].id == kTimerId) { | 273 if (msg[i].id == kTimerId) { |
274 LOG_INFO("HandleInterruptFd read timer update\n"); | 274 LOG_INFO("HandleInterruptFd read timer update\n"); |
275 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data); | 275 timeout_queue_.UpdateTimeout(msg[i].dart_port, msg[i].data); |
276 } else if (msg[i].id == kShutdownId) { | 276 } else if (msg[i].id == kShutdownId) { |
277 LOG_INFO("HandleInterruptFd read shutdown\n"); | 277 LOG_INFO("HandleInterruptFd read shutdown\n"); |
278 shutdown_ = true; | 278 shutdown_ = true; |
279 } else { | 279 } else { |
280 ASSERT((msg[i].data & COMMAND_MASK) != 0); | 280 ASSERT((msg[i].data & COMMAND_MASK) != 0); |
281 LOG_INFO("HandleInterruptFd command\n"); | 281 LOG_INFO("HandleInterruptFd command\n"); |
| 282 Socket* socket = reinterpret_cast<Socket*>(msg[i].id); |
| 283 RefCntReleaseScope<Socket> rs(socket); |
| 284 if (socket->fd() == -1) { |
| 285 continue; |
| 286 } |
282 DescriptorInfo* di = | 287 DescriptorInfo* di = |
283 GetDescriptorInfo(msg[i].id, IS_LISTENING_SOCKET(msg[i].data)); | 288 GetDescriptorInfo(socket->fd(), IS_LISTENING_SOCKET(msg[i].data)); |
284 if (IS_COMMAND(msg[i].data, kShutdownReadCommand)) { | 289 if (IS_COMMAND(msg[i].data, kShutdownReadCommand)) { |
285 ASSERT(!di->IsListeningSocket()); | 290 ASSERT(!di->IsListeningSocket()); |
286 // Close the socket for reading. | 291 // Close the socket for reading. |
287 LOG_INFO("\tSHUT_RD: %d\n", di->fd()); | 292 LOG_INFO("\tSHUT_RD: %d\n", di->fd()); |
288 VOID_NO_RETRY_EXPECTED(shutdown(di->fd(), SHUT_RD)); | 293 VOID_NO_RETRY_EXPECTED(shutdown(di->fd(), SHUT_RD)); |
289 } else if (IS_COMMAND(msg[i].data, kShutdownWriteCommand)) { | 294 } else if (IS_COMMAND(msg[i].data, kShutdownWriteCommand)) { |
290 ASSERT(!di->IsListeningSocket()); | 295 ASSERT(!di->IsListeningSocket()); |
291 // Close the socket for writing. | 296 // Close the socket for writing. |
292 LOG_INFO("\tSHUT_WR: %d\n", di->fd()); | 297 LOG_INFO("\tSHUT_WR: %d\n", di->fd()); |
293 VOID_NO_RETRY_EXPECTED(shutdown(di->fd(), SHUT_WR)); | 298 VOID_NO_RETRY_EXPECTED(shutdown(di->fd(), SHUT_WR)); |
(...skipping 10 matching lines...) Expand all Loading... |
304 intptr_t fd = di->fd(); | 309 intptr_t fd = di->fd(); |
305 if (di->IsListeningSocket()) { | 310 if (di->IsListeningSocket()) { |
306 // We only close the socket file descriptor from the operating | 311 // We only close the socket file descriptor from the operating |
307 // system if there are no other dart socket objects which | 312 // system if there are no other dart socket objects which |
308 // are listening on the same (address, port) combination. | 313 // are listening on the same (address, port) combination. |
309 ListeningSocketRegistry* registry = | 314 ListeningSocketRegistry* registry = |
310 ListeningSocketRegistry::Instance(); | 315 ListeningSocketRegistry::Instance(); |
311 | 316 |
312 MutexLocker locker(registry->mutex()); | 317 MutexLocker locker(registry->mutex()); |
313 | 318 |
314 if (registry->CloseSafe(fd)) { | 319 if (registry->CloseSafe(socket)) { |
315 ASSERT(new_mask == 0); | 320 ASSERT(new_mask == 0); |
316 socket_map_.Remove(GetHashmapKeyFromFd(fd), | 321 socket_map_.Remove(GetHashmapKeyFromFd(fd), |
317 GetHashmapHashFromFd(fd)); | 322 GetHashmapHashFromFd(fd)); |
318 di->Close(); | 323 di->Close(); |
319 LOG_INFO("Closed %d\n", di->fd()); | 324 LOG_INFO("Closed %d\n", di->fd()); |
320 delete di; | 325 delete di; |
| 326 socket->SetClosedFd(); |
321 } | 327 } |
322 } else { | 328 } else { |
323 ASSERT(new_mask == 0); | 329 ASSERT(new_mask == 0); |
324 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); | 330 socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd)); |
325 di->Close(); | 331 di->Close(); |
326 LOG_INFO("Closed %d\n", di->fd()); | 332 LOG_INFO("Closed %d\n", di->fd()); |
327 delete di; | 333 delete di; |
| 334 socket->SetClosedFd(); |
328 } | 335 } |
329 | 336 |
330 bool success = DartUtils::PostInt32(port, 1 << kDestroyedEvent); | 337 bool success = DartUtils::PostInt32(port, 1 << kDestroyedEvent); |
331 if (!success) { | 338 if (!success) { |
332 LOG_ERR("Failed to post destroy event to port %ld", port); | 339 LOG_ERR("Failed to post destroy event to port %ld", port); |
333 } | 340 } |
334 } else if (IS_COMMAND(msg[i].data, kReturnTokenCommand)) { | 341 } else if (IS_COMMAND(msg[i].data, kReturnTokenCommand)) { |
335 int count = TOKEN_COUNT(msg[i].data); | 342 int count = TOKEN_COUNT(msg[i].data); |
336 intptr_t old_mask = di->Mask(); | 343 intptr_t old_mask = di->Mask(); |
337 LOG_INFO("\t Return Token: %d: %lx\n", di->fd(), old_mask); | 344 LOG_INFO("\t Return Token: %d: %lx\n", di->fd(), old_mask); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 LOG_INFO("epoll_wait(millis = %ld) -> %ld\n", millis, result); | 468 LOG_INFO("epoll_wait(millis = %ld) -> %ld\n", millis, result); |
462 if (result < 0) { | 469 if (result < 0) { |
463 if (errno != EWOULDBLOCK) { | 470 if (errno != EWOULDBLOCK) { |
464 perror("Poll failed"); | 471 perror("Poll failed"); |
465 } | 472 } |
466 } else { | 473 } else { |
467 handler_impl->HandleTimeout(); | 474 handler_impl->HandleTimeout(); |
468 handler_impl->HandleEvents(events, result); | 475 handler_impl->HandleEvents(events, result); |
469 } | 476 } |
470 } | 477 } |
| 478 DEBUG_ASSERT(ReferenceCounted<Socket>::instances() == 0); |
471 handler->NotifyShutdownDone(); | 479 handler->NotifyShutdownDone(); |
472 } | 480 } |
473 | 481 |
474 | 482 |
475 void EventHandlerImplementation::Start(EventHandler* handler) { | 483 void EventHandlerImplementation::Start(EventHandler* handler) { |
476 int result = Thread::Start(&EventHandlerImplementation::Poll, | 484 int result = Thread::Start(&EventHandlerImplementation::Poll, |
477 reinterpret_cast<uword>(handler)); | 485 reinterpret_cast<uword>(handler)); |
478 if (result != 0) { | 486 if (result != 0) { |
479 FATAL1("Failed to start event handler thread %d", result); | 487 FATAL1("Failed to start event handler thread %d", result); |
480 } | 488 } |
(...skipping 21 matching lines...) Expand all Loading... |
502 // The hashmap does not support keys with value 0. | 510 // The hashmap does not support keys with value 0. |
503 return dart::Utils::WordHash(fd + 1); | 511 return dart::Utils::WordHash(fd + 1); |
504 } | 512 } |
505 | 513 |
506 } // namespace bin | 514 } // namespace bin |
507 } // namespace dart | 515 } // namespace dart |
508 | 516 |
509 #endif // defined(HOST_OS_FUCHSIA) | 517 #endif // defined(HOST_OS_FUCHSIA) |
510 | 518 |
511 #endif // !defined(DART_IO_DISABLED) | 519 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |