move generic sigar_net_connection_list_get impl to sigar.c

This commit is contained in:
Doug MacEachern 2006-07-01 16:47:47 +00:00
parent bf6984b477
commit b1798c3e2f
3 changed files with 44 additions and 36 deletions

View File

@ -1857,42 +1857,6 @@ int sigar_net_connection_walk(sigar_net_connection_walker_t *walker)
return SIGAR_OK;
}
static int net_connection_list_walker(sigar_net_connection_walker_t *walker,
sigar_net_connection_t *conn)
{
sigar_net_connection_list_t *connlist =
(sigar_net_connection_list_t *)walker->data;
SIGAR_NET_CONNLIST_GROW(connlist);
memcpy(&connlist->data[connlist->number++],
conn, sizeof(*conn));
return SIGAR_OK; /* continue loop */
}
int sigar_net_connection_list_get(sigar_t *sigar,
sigar_net_connection_list_t *connlist,
int flags)
{
int status;
sigar_net_connection_walker_t walker;
sigar_net_connection_list_create(connlist);
walker.sigar = sigar;
walker.flags = flags;
walker.data = connlist;
walker.add_connection = net_connection_list_walker;
status = sigar_net_connection_walk(&walker);
if (status != SIGAR_OK) {
sigar_net_connection_list_destroy(sigar, connlist);
}
return status;
}
#ifndef DARWIN
#define _KERNEL

View File

@ -35,4 +35,6 @@ struct sigar_t {
#define SIGAR_EPERM_KMEM (SIGAR_OS_START_ERROR+EACCES)
#define SIGAR_EPROC_NOENT (SIGAR_OS_START_ERROR+2)
#define SIGAR_USE_NET_CONNECTION_LIST_WALKER
#endif /* SIGAR_OS_H */

View File

@ -718,6 +718,48 @@ SIGAR_DECLARE(const char *)sigar_net_connection_state_get(int state)
return "UNKNOWN";
}
}
#ifdef SIGAR_USE_NET_CONNECTION_LIST_WALKER
/*
* implement sigar_net_connection_list_get using sigar_net_connection_walk
* linux has its own list_get impl. other platforms still need walker impl
*/
static int net_connection_list_walker(sigar_net_connection_walker_t *walker,
sigar_net_connection_t *conn)
{
sigar_net_connection_list_t *connlist =
(sigar_net_connection_list_t *)walker->data;
SIGAR_NET_CONNLIST_GROW(connlist);
memcpy(&connlist->data[connlist->number++],
conn, sizeof(*conn));
return SIGAR_OK; /* continue loop */
}
int sigar_net_connection_list_get(sigar_t *sigar,
sigar_net_connection_list_t *connlist,
int flags)
{
int status;
sigar_net_connection_walker_t walker;
sigar_net_connection_list_create(connlist);
walker.sigar = sigar;
walker.flags = flags;
walker.data = connlist;
walker.add_connection = net_connection_list_walker;
status = sigar_net_connection_walk(&walker);
if (status != SIGAR_OK) {
sigar_net_connection_list_destroy(sigar, connlist);
}
return status;
}
#endif
#if defined(__linux__) /* XXX need to implement walker on other platforms */
typedef struct {
sigar_net_stat_t *netstat;