From 562e2e243e69f128c47ceb59c5b1710fa35c7081 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 12 Mar 2011 08:58:35 +0000 Subject: inet_diag: small reorganization --- ext/raindrops/linux_inet_diag.c | 64 ++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/ext/raindrops/linux_inet_diag.c b/ext/raindrops/linux_inet_diag.c index 160f90b..386b87c 100644 --- a/ext/raindrops/linux_inet_diag.c +++ b/ext/raindrops/linux_inet_diag.c @@ -83,6 +83,20 @@ static int st_free_data(st_data_t key, st_data_t value, st_data_t ignored) return ST_DELETE; } +static int st_to_hash(st_data_t key, st_data_t value, VALUE hash) +{ + struct listen_stats *stats = (struct listen_stats *)value; + + if (stats->listener_p) { + VALUE k = rb_str_new2((const char *)key); + VALUE v = rb_listen_stats(stats); + + OBJ_FREEZE(k); + rb_hash_aset(hash, k, v); + } + return st_free_data(key, value, 0); +} + static struct listen_stats *stats_for(st_table *table, struct inet_diag_msg *r) { char *key, *port; @@ -359,6 +373,24 @@ static void parse_addr(struct sockaddr_storage *inet, VALUE addr) freeaddrinfo(res); } +/* generates inet_diag bytecode to match all addrs for a given family */ +static void gen_bytecode_all(struct iovec *iov, sa_family_t family) +{ + struct inet_diag_bc_op *op; + struct inet_diag_hostcond *cond; + + /* iov_len was already set and base allocated in a parent function */ + assert(iov->iov_len == OPLEN && iov->iov_base && "iov invalid"); + op = iov->iov_base; + op->code = INET_DIAG_BC_S_COND; + op->yes = OPLEN; + op->no = sizeof(struct inet_diag_bc_op) + OPLEN; + cond = (struct inet_diag_hostcond *)(op + 1); + cond->family = family; + cond->port = -1; + cond->prefix_len = 0; +} + /* generates inet_diag bytecode to match a single addr */ static void gen_bytecode(struct iovec *iov, struct sockaddr_storage *inet) { @@ -460,38 +492,6 @@ static VALUE tcp_listener_stats(VALUE obj, VALUE addrs) return rv; } -static int st_to_hash(st_data_t key, st_data_t value, VALUE hash) -{ - struct listen_stats *stats = (struct listen_stats *)value; - - if (stats->listener_p) { - VALUE k = rb_str_new2((const char *)key); - VALUE v = rb_listen_stats(stats); - - OBJ_FREEZE(k); - rb_hash_aset(hash, k, v); - } - return st_free_data(key, value, 0); -} - -/* generates inet_diag bytecode to match all addrs for a given family */ -static void gen_bytecode_all(struct iovec *iov, sa_family_t family) -{ - struct inet_diag_bc_op *op; - struct inet_diag_hostcond *cond; - - /* iov_len was already set and base allocated in a parent function */ - assert(iov->iov_len == OPLEN && iov->iov_base && "iov invalid"); - op = iov->iov_base; - op->code = INET_DIAG_BC_S_COND; - op->yes = OPLEN; - op->no = sizeof(struct inet_diag_bc_op) + OPLEN; - cond = (struct inet_diag_hostcond *)(op + 1); - cond->family = family; - cond->port = -1; - cond->prefix_len = 0; -} - static VALUE all_tcp_listener_stats(VALUE obj) { VALUE rv; -- cgit v1.2.3-24-ge0c7