Fixes to shutdown...

This commit is contained in:
Jan Vidar Krey
2009-08-03 23:59:02 +02:00
parent fbe98d6011
commit eca0f931bd
10 changed files with 120 additions and 65 deletions

View File

@@ -107,7 +107,7 @@ void net_con_initialize(struct net_connection* con, int sd, struct ip_addr_encap
if (events & EV_WRITE) net_con_flag_set(con, NET_WANT_WRITE);
event_set(&con->event, con->sd, events | EV_PERSIST, net_con_event, con);
event_base_set(g_hub->evbase, &con->event);
event_base_set(net_get_evbase(), &con->event);
event_add(&con->event, 0);
net_set_nonblocking(sd, 1);
@@ -134,9 +134,12 @@ void net_con_update(struct net_connection* con, int events)
void net_con_close(struct net_connection* con)
{
if (!event_pending(&con->event, EV_READ | EV_WRITE, 0))
return;
event_del(&con->event);
if (event_pending(&con->event, EV_READ | EV_WRITE, 0))
{
event_del(&con->event);
}
net_con_clear_timeout(con);
net_close(con->sd);
con->sd = -1;
}
@@ -291,7 +294,7 @@ void net_con_set_timeout(struct net_connection* con, int seconds)
{
struct timeval timeout = { seconds, 0 };
evtimer_set(&con->timeout, net_con_event, con);
event_base_set(g_hub->evbase, &con->timeout);
event_base_set(net_get_evbase(), &con->timeout);
evtimer_add(&con->timeout, &timeout);
}

View File

@@ -21,6 +21,7 @@
static int is_ipv6_supported = -1; /* -1 = CHECK, 0 = NO, 1 = YES */
static int net_initialized = 0;
static struct event_base* net_evbase = 0;
static struct net_statistics stats;
static struct net_statistics stats_total;
@@ -35,6 +36,7 @@ int net_initialize()
{
if (!net_initialized)
{
LOG_TRACE("Initializing network monitor.");
#ifdef WINSOCK
struct WSAData wsa;
@@ -45,7 +47,18 @@ int net_initialize()
}
#endif /* WINSOCK */
LOG_TRACE("Initializing network monitor.");
#ifdef LIBEVENT_1_4
net_evbase = event_base_new();
#else
net_evbase = event_init();
#endif
if (!net_evbase)
{
LOG_ERROR("Unable to initialize libevent.");
return 0;
}
LOG_DEBUG("Using libevent %s, backend: %s", event_get_version(), event_get_method());
net_stats_initialize();
#ifdef SSL_SUPPORT
@@ -83,6 +96,9 @@ int net_destroy()
{
LOG_TRACE("Shutting down network monitor");
event_base_free(net_evbase);
net_evbase = 0;
#ifdef SSL_SUPPORT
/* FIXME: Shutdown OpenSSL here. */
#endif
@@ -96,6 +112,11 @@ int net_destroy()
return -1;
}
struct event_base* net_get_evbase()
{
return net_evbase;
}
static void net_error_out(int fd, const char* func)
{
int err = net_error();

View File

@@ -66,6 +66,8 @@ extern int net_initialize();
*/
extern int net_destroy();
extern struct event_base* net_get_evbase();
/**
* @return the number of sockets currrently being monitored.
*/