| Index: dart/runtime/bin/eventhandler_linux.cc
|
| diff --git a/dart/runtime/bin/eventhandler_linux.cc b/dart/runtime/bin/eventhandler_linux.cc
|
| index 97b305b61e39d05aff432978f25ef07cf846879a..ada31643617642b34dbf248ea44cdff86f53930b 100644
|
| --- a/dart/runtime/bin/eventhandler_linux.cc
|
| +++ b/dart/runtime/bin/eventhandler_linux.cc
|
| @@ -6,6 +6,7 @@
|
| #if defined(TARGET_OS_LINUX)
|
|
|
| #include "bin/eventhandler.h"
|
| +#include "bin/eventhandler_linux.h"
|
|
|
| #include <errno.h> // NOLINT
|
| #include <pthread.h> // NOLINT
|
| @@ -20,6 +21,7 @@
|
| #include "bin/dartutils.h"
|
| #include "bin/fdutils.h"
|
| #include "bin/log.h"
|
| +#include "bin/lockers.h"
|
| #include "bin/socket.h"
|
| #include "bin/thread.h"
|
| #include "platform/utils.h"
|
| @@ -210,12 +212,34 @@ void EventHandlerImplementation::HandleInterruptFd() {
|
| } else if (IS_COMMAND(msg[i].data, kCloseCommand)) {
|
| // Close the socket and free system resources and move on to next
|
| // message.
|
| - if (sd->RemovePort(msg[i].dart_port)) {
|
| + bool no_more_listeners = sd->RemovePort(msg[i].dart_port);
|
| + if (no_more_listeners) {
|
| RemoveFromEpollInstance(epoll_fd_, sd);
|
| + }
|
| +
|
| + if (sd->IsListeningSocket()) {
|
| intptr_t fd = sd->fd();
|
| - sd->Close();
|
| - socket_map_.Remove(GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd));
|
| - delete sd;
|
| + // We only close the socket file descriptor from the operating
|
| + // system if there are no other dart socket objects which
|
| + // are listening on the same (address, port) combination.
|
| + {
|
| + MutexLocker ml(globalTcpListeningSocketRegistry.mutex());
|
| + if (globalTcpListeningSocketRegistry.CloseSafe(sd->fd())) {
|
| + ASSERT(no_more_listeners);
|
| + socket_map_.Remove(
|
| + GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd));
|
| + sd->Close();
|
| + delete sd;
|
| + }
|
| + }
|
| + } else {
|
| + if (no_more_listeners) {
|
| + intptr_t fd = sd->fd();
|
| + socket_map_.Remove(
|
| + GetHashmapKeyFromFd(fd), GetHashmapHashFromFd(fd));
|
| + sd->Close();
|
| + delete sd;
|
| + }
|
| }
|
| DartUtils::PostInt32(msg[i].dart_port, 1 << kDestroyedEvent);
|
| } else if (IS_COMMAND(msg[i].data, kReturnTokenCommand)) {
|
| @@ -333,7 +357,7 @@ void EventHandlerImplementation::Poll(uword args) {
|
|
|
| void EventHandlerImplementation::Start(EventHandler* handler) {
|
| int result = Thread::Start(&EventHandlerImplementation::Poll,
|
| - reinterpret_cast<uword>(handler));
|
| + reinterpret_cast<uword>(handler));
|
| if (result != 0) {
|
| FATAL1("Failed to start event handler thread %d", result);
|
| }
|
|
|