Noux: add cleanup_socket_descriptors() function

When a child exists it makes sure that all remaining socket descriptors
are closed.
This commit is contained in:
Josef Söntgen 2012-08-21 14:38:09 +02:00 committed by Norman Feske
parent 2010a74fba
commit 8dfb3d5d81
3 changed files with 21 additions and 1 deletions

View File

@ -31,6 +31,8 @@
#include <cpu_session_component.h>
#include <child_policy.h>
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);

View File

@ -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; }

View File

@ -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<Socket_io_channel>::instance()->remove_io_channel(sd);
if (Socket_descriptor_registry<Socket_io_channel>::instance()->sd_in_use(sd)) {
Socket_descriptor_registry<Socket_io_channel>::instance()->remove_io_channel(sd);
}
}
static void _cleanup_socket_descriptors()
{
Socket_descriptor_registry<Socket_io_channel>::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;
}
/*********************************