Navigation


Changeset 25:67ca08d5bc48 in freeDiameter for include


Ignore:
Timestamp:
Oct 26, 2009, 4:00:49 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Completed connection context files

Location:
include/freeDiameter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/freeDiameter/freeDiameter.h

    r24 r25  
    152152struct fd_event {
    153153        int      code; /* codespace depends on the queue */
     154        size_t   size;
    154155        void    *data;
    155156};
    156157
    157 static __inline__ int fd_event_send(struct fifo *queue, int code, void * data)
    158 {
    159         struct fd_event * ev;
    160         CHECK_MALLOC( ev = malloc(sizeof(struct fd_event)) );
    161         ev->code = code;
    162         ev->data = data;
    163         CHECK_FCT( fd_fifo_post(queue, &ev) );
    164         return 0;
    165 }
    166 static __inline__ int fd_event_get(struct fifo *queue, int *code, void ** data)
    167 {
    168         struct fd_event * ev;
    169         CHECK_FCT( fd_fifo_get(queue, &ev) );
    170         if (code)
    171                 *code = ev->code;
    172         if (data)
    173                 *data = ev->data;
    174         free(ev);
    175         return 0;
    176 }
    177 
    178 /* Events codespace for fd_g_config->cnf_main_ev */
     158/* Daemon's codespace: 1000->1999 */
    179159enum {
    180          FDEV_TERMINATE = 1000  /* request to terminate */
     160         FDEV_TERMINATE = 1000  /* request to terminate */
    181161        ,FDEV_DUMP_DICT         /* Dump the content of the dictionary */
    182162        ,FDEV_DUMP_EXT          /* Dump state of extensions */
     
    186166        ,FDEV_DUMP_PEERS        /* Dump the list of peers */
    187167};
     168
     169static __inline__ int fd_event_send(struct fifo *queue, int code, size_t datasz, void * data)
     170{
     171        struct fd_event * ev;
     172        CHECK_MALLOC( ev = malloc(sizeof(struct fd_event)) );
     173        ev->code = code;
     174        ev->size = datasz;
     175        ev->data = data;
     176        CHECK_FCT( fd_fifo_post(queue, &ev) );
     177        return 0;
     178}
     179static __inline__ int fd_event_get(struct fifo *queue, int *code, size_t *datasz, void ** data)
     180{
     181        struct fd_event * ev;
     182        CHECK_FCT( fd_fifo_get(queue, &ev) );
     183        if (code)
     184                *code = ev->code;
     185        if (datasz)
     186                *datasz = ev->size;
     187        if (data)
     188                *data = ev->data;
     189        free(ev);
     190        return 0;
     191}
     192static __inline__ int fd_event_timedget(struct fifo *queue, struct timespec * timeout, int timeoutcode, int *code, size_t *datasz, void ** data)
     193{
     194        struct fd_event * ev;
     195        int ret = 0;
     196        ret = fd_fifo_timedget(queue, &ev, timeout);
     197        if (ret == ETIMEDOUT) {
     198                if (code)
     199                        *code = timeoutcode;
     200                if (datasz)
     201                        *datasz = 0;
     202                if (data)
     203                        *data = NULL;
     204        } else {
     205                CHECK_FCT( ret );
     206                if (code)
     207                        *code = ev->code;
     208                if (datasz)
     209                        *datasz = ev->size;
     210                if (data)
     211                        *data = ev->data;
     212                free(ev);
     213        }
     214        return 0;
     215}
     216static __inline__ void fd_event_destroy(struct fifo **queue, void (*free_cb)(void * data))
     217{
     218        struct fd_event * ev;
     219        /* Purge all events, and free the associated data if any */
     220        while (fd_fifo_tryget( *queue, &ev ) == 0) {
     221                (*free_cb)(ev->data);
     222                free(ev);
     223        }
     224        CHECK_FCT_DO( fd_fifo_del(queue), /* continue */ );
     225        return ;
     226
    188227const char * fd_ev_str(int event); /* defined in freeDiameter/main.c */
    189228
  • include/freeDiameter/libfreeDiameter.h

    r24 r25  
    427427
    428428
     429/* Trace a binary buffer content */
     430#define TRACE_DEBUG_BUFFER(level, prefix, buf, bufsz, suffix ) {                                                                \
     431        if ( TRACE_BOOL(level) ) {                                                                                              \
     432                int __i;                                                                                                        \
     433                size_t __sz = (size_t)(bufsz);                                                                                  \
     434                uint8_t * __buf = (uint8_t *)(buf);                                                                             \
     435                char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed");                                       \
     436                fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n"                                                                \
     437                          "\t%s|%*s" prefix ,                                                                                   \
     438                                        __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\
     439                                        (level < FULL)?"@":" ",level, "");                                                      \
     440                for (__i = 0; __i < __sz; __i++) {                                                                              \
     441                        fd_log_debug("%02.2hhx", __buf[__i]);                                                                   \
     442                }                                                                                                               \
     443                fd_log_debug(suffix "\n");                                                                                      \
     444        }                                                                                                                       \
     445}
     446
     447
     448
    429449/*============================================================*/
    430450/*                          THREADS                           */
     
    508528void fd_list_insert_after  ( struct fd_list * ref, struct fd_list * item );
    509529void fd_list_insert_before ( struct fd_list * ref, struct fd_list * item );
     530
     531/* Move a list at the end of another */
     532void fd_list_move_end(struct fd_list * ref, struct fd_list * senti);
    510533
    511534/* Insert an item in an ordered list -- ordering function provided. If duplicate object found, EEXIST and it is returned in ref_duplicate */
     
    23852408
    23862409/*
     2410 * FUNCTION:    fd_fifo_move
     2411 *
     2412 * PARAMETERS:
     2413 *  old         : Location of a FIFO that is to be emptied and deleted.
     2414 *  new         : A FIFO that will receive the old data.
     2415 *  loc_update  : if non NULL, a place to store the pointer to new FIFO atomically with the move.
     2416 *
     2417 * DESCRIPTION:
     2418 *  Delete a queue and move its content to another one atomically.
     2419 *
     2420 * RETURN VALUE:
     2421 *  0           : The queue has been destroyed successfully.
     2422 *  EINVAL      : A parameter is invalid.
     2423 */
     2424int fd_fifo_move ( struct fifo ** old, struct fifo * new, struct fifo ** loc_update );
     2425
     2426/*
    23872427 * FUNCTION:    fd_fifo_length
    23882428 *
Note: See TracChangeset for help on using the changeset viewer.