save listen port address as cache val for later use

This commit is contained in:
Doug MacEachern 2007-04-06 12:27:32 +00:00
parent 614fd63728
commit fbaa233617
1 changed files with 15 additions and 11 deletions

View File

@ -845,16 +845,25 @@ sigar_net_connection_list_get(sigar_t *sigar,
} }
#endif #endif
static void sigar_net_listen_address_add(sigar_t *sigar,
sigar_net_connection_t *conn)
{
sigar_cache_entry_t *entry =
sigar_cache_get(sigar->net_listen, conn->local_port);
if (!entry->value) {
entry->value = malloc(sizeof(conn->local_address));
}
memcpy(entry->value, &conn->local_address,
sizeof(conn->local_address));
}
typedef struct { typedef struct {
sigar_net_stat_t *netstat; sigar_net_stat_t *netstat;
sigar_net_connection_list_t *connlist; sigar_net_connection_list_t *connlist;
} net_stat_getter_t; } net_stat_getter_t;
static void listen_port_free(void *ptr)
{
/*noop*/
}
static int net_stat_walker(sigar_net_connection_walker_t *walker, static int net_stat_walker(sigar_net_connection_walker_t *walker,
sigar_net_connection_t *conn) sigar_net_connection_t *conn)
{ {
@ -868,11 +877,7 @@ static int net_stat_walker(sigar_net_connection_walker_t *walker,
/* XXX listen_ports may get stale */ /* XXX listen_ports may get stale */
if (state == SIGAR_TCP_LISTEN) { if (state == SIGAR_TCP_LISTEN) {
sigar_cache_entry_t *entry = sigar_net_listen_address_add(walker->sigar, conn);
sigar_cache_get(listen_ports,
conn->local_port);
entry->value = (void*)conn->local_port;
} }
else { else {
if (sigar_cache_find(listen_ports, if (sigar_cache_find(listen_ports,
@ -908,7 +913,6 @@ sigar_net_stat_get(sigar_t *sigar,
if (!sigar->net_listen) { if (!sigar->net_listen) {
sigar->net_listen = sigar_cache_new(32); sigar->net_listen = sigar_cache_new(32);
sigar->net_listen->free_value = listen_port_free;
} }
SIGAR_ZERO(netstat); SIGAR_ZERO(netstat);