diff --git a/ports/src/noux/child.h b/ports/src/noux/child.h index f04a8bdb93..aefac5a1b3 100644 --- a/ports/src/noux/child.h +++ b/ports/src/noux/child.h @@ -31,6 +31,8 @@ #include #include +extern void (*cleanup_socket_descriptors)(); + namespace Noux { /** @@ -338,6 +340,10 @@ namespace Noux { ~Child() { + /* short-cut to close all remaining open sd's if the child exits */ + if (cleanup_socket_descriptors) + cleanup_socket_descriptors(); + _sig_rec->dissolve(&_execve_cleanup_dispatcher); _sig_rec->dissolve(&_exit_dispatcher); diff --git a/ports/src/noux/minimal/dummy_net.cc b/ports/src/noux/minimal/dummy_net.cc index 4a6869a0e8..9d1780f3cc 100644 --- a/ports/src/noux/minimal/dummy_net.cc +++ b/ports/src/noux/minimal/dummy_net.cc @@ -16,6 +16,8 @@ void (*close_socket)(int) = 0; +void (*cleanup_socket_descriptors)() = 0; + void init_network() { } bool Noux::Child::_syscall_net(Noux::Session::Syscall sc) { return false; } diff --git a/ports/src/noux/net/net.cc b/ports/src/noux/net/net.cc index 482ab55069..d76786fc88 100644 --- a/ports/src/noux/net/net.cc +++ b/ports/src/noux/net/net.cc @@ -33,6 +33,7 @@ using namespace Noux; void (*libc_select_notify)(); void (*close_socket)(int); +void (*cleanup_socket_descriptors)(); /* set select() timeout to lwip's lowest possible value */ struct timeval timeout = { 0, 10000 }; @@ -95,7 +96,15 @@ static void select_notify() static void _close_socket(int sd) { - Socket_descriptor_registry::instance()->remove_io_channel(sd); + if (Socket_descriptor_registry::instance()->sd_in_use(sd)) { + Socket_descriptor_registry::instance()->remove_io_channel(sd); + } +} + + +static void _cleanup_socket_descriptors() +{ + Socket_descriptor_registry::instance()->reset_all(); } @@ -121,6 +130,9 @@ void init_network() if (!close_socket) close_socket = _close_socket; + + if (!cleanup_socket_descriptors) + cleanup_socket_descriptors = _cleanup_socket_descriptors; } /*********************************