/* This function does some simple tests to ensure that the fdtable makes sense. * There are many more tests we could do; feel free to add them at your * leisure! */ void citp_fdtable_assert_valid(void) { int i; if( ! citp_fdtable.table ) return; CITP_FDTABLE_LOCK_RD(); for( i = 0; i < citp_fdtable.inited_count; i++ ) { citp_fdinfo_p fdip = citp_fdtable.table[i].fdip; if( fdip_is_normal(fdip) ) { citp_fdinfo * fdi = fdip_to_fdi(fdip); ci_assert(fdi); ci_assert(fdi->protocol); if( ( fdi->protocol->type == CITP_TCP_SOCKET || fdi->protocol->type == CITP_UDP_SOCKET ) && fdi_to_socket(fdi)->s ) ci_assert(! (fdi_to_socket(fdi)->s->b.sb_aflags & CI_SB_AFLAG_ORPHAN)); if (!fdi->is_special) { /* Ensure the "back pointer" makes sense */ ci_assert (fdi->fd == i); /* Ensure that the reference count is in a vaguely sensible range */ ci_assert ((oo_atomic_read (&fdi->ref_count) > 0) && (oo_atomic_read (&fdi->ref_count) < 10000)); /* 10,000 threads is a bit mad, warn if more than 20 */ if (oo_atomic_read (&fdi->ref_count) > 20) { Log_U (log ("Warning: fd %d's ref-count suspiciously large (%d)\n", i, oo_atomic_read (&fdi->ref_count))); } } } } CITP_FDTABLE_UNLOCK_RD(); }
static void citp_udp_dtor(citp_fdinfo* fdinfo, int fdt_locked) { citp_netif_release_ref(fdi_to_socket(fdinfo)->netif, fdt_locked); }