diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/qtimers.c | 40 | ||||
-rw-r--r-- | lib/qtimers.h | 3 | ||||
-rw-r--r-- | lib/sockunion.c | 57 | ||||
-rw-r--r-- | lib/sockunion.h | 7 |
4 files changed, 103 insertions, 4 deletions
diff --git a/lib/qtimers.c b/lib/qtimers.c index 43335d55..a5d0e27b 100644 --- a/lib/qtimers.c +++ b/lib/qtimers.c @@ -154,6 +154,8 @@ qtimer_pile_dispatch_next(qtimer_pile qtp, qtime_mono_t upto) { qtimer qtr ; + qtimer_pile_verify(qtp) ; /* TODO: remove after debuggery */ + qtr = heap_top_item(&qtp->timers) ; if ((qtr != NULL) && (qtr->time <= upto)) { @@ -321,6 +323,7 @@ qtimer_set(qtimer qtr, qtime_mono_t when, qtimer_action* action) qtp = qtr->pile ; dassert(qtp != NULL) ; assert(qtp == our_pile); + qtimer_pile_verify(qtp) ; /* TODO: remove after debuggery */ qtr->time = when ; @@ -328,7 +331,9 @@ qtimer_set(qtimer qtr, qtime_mono_t when, qtimer_action* action) heap_update_item(&qtp->timers, qtr) ; /* update in heap */ else heap_push_item(&qtp->timers, qtr) ; /* add to heap */ + assert(qtp == qtr->pile); + qtimer_pile_verify(qtp) ; /* TODO: remove after debuggery */ qtr->state = qtr_state_active ; /* overrides any unset pending */ @@ -349,11 +354,46 @@ qtimer_unset(qtimer qtr) { qtimer_pile qtp = qtr->pile ; dassert(qtp != NULL) ; + assert(qtp == our_pile); + qtimer_pile_verify(qtp) ; /* TODO: remove after debuggery */ heap_delete_item(&qtp->timers, qtr) ; + assert(qtp == qtr->pile); + qtimer_pile_verify(qtp) ; /* TODO: remove after debuggery */ qtr->state = qtr_state_inactive ; /* overrides any unset pending */ } ; } ; + +/*============================================================================== + * Verification code for debug purposes. + */ +extern void +qtimer_pile_verify(qtimer_pile qtp) +{ + heap th = &qtp->timers ; + vector v ; + vector_index i ; + vector_index e ; + qtimer qtr ; + + /* Eclipse flags offsetof(struct qtimer, backlink) as a syntax error :-( */ + typedef struct qtimer qtimer_t ; + + assert(th->cmp == (heap_cmp*)qtimer_cmp) ; + assert(th->state == Heap_Has_Backlink) ; + assert(th->backlink_offset == offsetof(qtimer_t, backlink)) ; + + v = &th->v ; + e = vector_end(v) ; + for (i = 0 ; i < e ; ++i) + { + qtr = vector_get_item(v, i) ; + + assert(qtr->pile == qtp) ; + assert(qtr->backlink == i) ; + assert(qtr->action != NULL) ; + } ; +} ; diff --git a/lib/qtimers.h b/lib/qtimers.h index d4305dc0..3d509acb 100644 --- a/lib/qtimers.h +++ b/lib/qtimers.h @@ -132,6 +132,9 @@ qtimer_add_interval(qtimer qtr, qtimer_action* action) ; Inline qtime_t qtimer_get_interval(qtimer qtr) ; +void +qtimer_pile_verify(qtimer_pile qtp) ; + /*============================================================================== * Inline functions */ diff --git a/lib/sockunion.c b/lib/sockunion.c index d1fdb189..dbfccfb8 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -732,12 +732,63 @@ sockunion_free (union sockunion *su) } /*============================================================================== - * Clear a given sockunion -- ie zeroise it + * Sockunion reference utilities + */ + +/*------------------------------------------------------------------------------ + * Unset pointer to sockunion -- free any sockunion referenced + * + * Does nothing if there is no sockunion + */ +extern void +sockunion_unset(sockunion* p_su) +{ + if (*p_su != NULL) + XFREE(MTYPE_BGP_NOTIFY, *p_su) ; /* sets *p_su NULL */ +} ; + +/*------------------------------------------------------------------------------ + * Set pointer to sockunion (if any) + * + * Frees any existing sockunion at the destination. + * + * NB: copies the source pointer -- so must be clear about responsibility + * for the sockunion. + */ +extern void +sockunion_set(sockunion* p_dst, sockunion su) +{ + sockunion_unset(p_dst) ; + *p_dst = su ; +} + +/*------------------------------------------------------------------------------ + * Set pointer to a *copy* of the given sockunion + * + * Frees any existing sockunion at the destination. + * + * NB: copies the source pointer -- so must be clear about responsibility + * for the sockunion structure. + */ +extern void +sockunion_set_dup(sockunion* p_dst, sockunion su) +{ + sockunion_set(p_dst, sockunion_dup(su)) ; +} ; + +/*------------------------------------------------------------------------------ + * Set pointer to sockunion (if any) and unset source pointer. + * + * Frees any existing sockunion at the destination. + * + * NB: responsibility for the sockunion passes to the destination. */ extern void -sockunion_clear(union sockunion* su) +sockunion_set_mov(sockunion* p_dst, sockunion* p_src) { - memset(su, 0, sizeof(union sockunion)) ; + sockunion_unset(p_dst) ; + *p_dst = *p_src ; + *p_src = NULL ; } ; /*============================================================================== diff --git a/lib/sockunion.h b/lib/sockunion.h index 8fcaded4..c00c02e4 100644 --- a/lib/sockunion.h +++ b/lib/sockunion.h @@ -41,6 +41,7 @@ union sockunion { #define su_port su_si.si_port #endif /* 0 */ +typedef union sockunion* sockunion ; union sockunion { struct sockaddr sa; @@ -118,7 +119,11 @@ extern int sockunion_getsockname (int, union sockunion*); extern int sockunion_getpeername (int, union sockunion*); extern union sockunion *sockunion_dup (union sockunion *); extern void sockunion_free (union sockunion *); -extern void sockunion_clear(union sockunion*); + +extern void sockunion_unset(sockunion* p_su) ; +extern void sockunion_set(sockunion* p_dst, sockunion su) ; +extern void sockunion_set_dup(sockunion* p_dst, sockunion su) ; +extern void sockunion_set_mov(sockunion* p_dst, sockunion* p_src) ; #ifndef HAVE_INET_NTOP extern const char * inet_ntop (int family, const void *addrptr, |