Navigation


Changeset 1014:908ffbb81f60 in freeDiameter for libfdcore


Ignore:
Timestamp:
Mar 29, 2013, 6:30:59 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation

Location:
libfdcore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/fdcore-internal.h

    r1010 r1014  
    134134        pthread_mutex_t mtx; /* mutex to protect these lists */
    135135        pthread_cond_t  cnd; /* cond var used by the thread that handles timeouts */
    136         pthread_t       thr; /* the thread that handles timeouts (and calls the anscb) */
     136        pthread_t       thr; /* the thread that handles timeouts (expirecb called in separate forked threads) */
    137137};
    138138
  • libfdcore/messages.c

    r928 r1014  
    321321       
    322322        /* Save the callback in the message */
    323         CHECK_FCT(  fd_msg_anscb_associate( *pmsg, anscb, data, NULL /* we should maybe use a safeguard here like 1 hour or so? */ )  );
     323        CHECK_FCT(  fd_msg_anscb_associate( *pmsg, anscb, data, NULL, NULL /* we should maybe use a safeguard here like 1 hour or so? */ )  );
    324324       
    325325        /* Post the message in the outgoing queue */
     
    330330
    331331/* The variation of the same function with a timeout callback */
    332 int fd_msg_send_timeout ( struct msg ** pmsg, void (*anscb)(void *, struct msg **), void * data, const struct timespec *timeout )
    333 {
    334         TRACE_ENTRY("%p %p %p", pmsg, anscb, data, timeout);
    335         CHECK_PARAMS( pmsg && anscb && timeout );
     332int fd_msg_send_timeout ( struct msg ** pmsg, void (*anscb)(void *, struct msg **), void * data, void (*expirecb)(void *, DiamId_t, size_t, struct msg **), const struct timespec *timeout )
     333{
     334        TRACE_ENTRY("%p %p %p %p %p", pmsg, anscb, data, expirecb, timeout);
     335        CHECK_PARAMS( pmsg && expirecb && timeout );
    336336       
    337337        /* Save the callback in the message, with the timeout */
    338         CHECK_FCT(  fd_msg_anscb_associate( *pmsg, anscb, data, timeout )  );
     338        CHECK_FCT(  fd_msg_anscb_associate( *pmsg, anscb, data, expirecb, timeout )  );
    339339       
    340340        /* Post the message in the outgoing queue */
  • libfdcore/p_sr.c

    r974 r1014  
    8585}
    8686
     87struct expire_data {
     88        struct msg * request;
     89        struct fd_peer * sentto;
     90};
     91
    8792/* (detached) thread that calls the anscb on expired messages.
    8893  We do it in a separate thread to avoid blocking the reception of new messages during this time */
    89 static void * call_anscb_expire(void * arg) {
    90         struct msg * expired_req = arg;
    91        
    92         void (*anscb)(void *, struct msg **);
     94static void * call_expirecb(void * arg) {
     95        struct expire_data * ed = arg;
     96       
     97        void (*expirecb)(void *, DiamId_t, size_t, struct msg **);
    9398        void * data;
    9499       
     
    103108       
    104109        /* Retrieve callback in the message */
    105         CHECK_FCT_DO( fd_msg_anscb_get( expired_req, &anscb, &data ), return NULL);
    106         ASSERT(anscb);
     110        CHECK_FCT_DO( fd_msg_anscb_get( ed->request, NULL, &expirecb, &data ), return NULL);
     111        ASSERT(expirecb);
    107112       
    108113        /* Clean up this data from the message */
    109         CHECK_FCT_DO( fd_msg_anscb_associate( expired_req, NULL, NULL, NULL ), return NULL);
     114        CHECK_FCT_DO( fd_msg_anscb_associate( ed->request, NULL, NULL, NULL, NULL ), return NULL);
    110115
    111116        /* Call it */
    112         (*anscb)(data, &expired_req);
     117        (*expirecb)(data, ed->sentto->p_hdr.info.pi_diamid, ed->sentto->p_hdr.info.pi_diamidlen, &ed->request);
    113118       
    114119        /* If the callback did not dispose of the message, do it now */
    115         if (expired_req) {
    116                 fd_msg_log(FD_MSG_LOG_DROPPED, expired_req, "Expiration period completed without an answer, and the expiry callback did not dispose of the message.");
    117                 CHECK_FCT_DO( fd_msg_free(expired_req), /* ignore */ );
    118         }
     120        if (ed->request) {
     121                fd_msg_log(FD_MSG_LOG_DROPPED, ed->request, "Expiration period completed without an answer, and the expiry callback did not dispose of the message.");
     122                CHECK_FCT_DO( fd_msg_free(ed->request), /* ignore */ );
     123        }
     124       
     125        free(ed);
    119126       
    120127        /* Finish */
     
    125132static void * sr_expiry_th(void * arg) {
    126133        struct sr_list * srlist = arg;
    127         struct msg * expired_req;
    128134        pthread_attr_t detached;
     135        struct expire_data * ed;
    129136       
    130137        TRACE_ENTRY("%p", arg);
     
    177184               
    178185                /* Now, the first request in the list is expired; remove it and call the anscb for it in a new thread */
     186                CHECK_MALLOC_DO( ed = malloc(sizeof(struct expire_data)), goto error );
     187                ed->sentto = first->chain.head->o;
     188                ed->request = first->req;
    179189                fd_list_unlink(&first->chain);
    180190                fd_list_unlink(&first->expire);
    181                 expired_req = first->req;
    182191                free(first);
    183192               
    184                 CHECK_POSIX_DO( pthread_create( &th, &detached, call_anscb_expire, expired_req ), goto error );
     193                CHECK_POSIX_DO( pthread_create( &th, &detached, call_expirecb, ed ), goto error );
    185194
    186195                /* loop */
  • libfdcore/routing_dispatch.c

    r974 r1014  
    467467
    468468                /* Retrieve any registered handler */
    469                 CHECK_FCT( fd_msg_anscb_get( qry, &anscb, &data ) );
     469                CHECK_FCT( fd_msg_anscb_get( qry, &anscb, NULL, &data ) );
    470470
    471471                /* If a callback was registered, pass the message to it */
     
    793793        struct rtd_candidate * c;
    794794        struct msg *msgptr = msg;
     795        DiamId_t qry_src = NULL;
     796        size_t qry_src_len = 0;
    795797       
    796798        /* Read the message header */
     
    801803        if ( ! is_req ) {
    802804                struct msg * qry;
    803                 DiamId_t qry_src = NULL;
    804                 size_t qry_src_len = 0;
    805805                struct msg_hdr * qry_hdr;
    806806                struct fd_peer * peer = NULL;
     
    832832       
    833833        /* From that point, the message is a request */
     834        CHECK_FCT( fd_msg_source_get( msgptr, &qry_src, &qry_src_len ) );
     835        /* if qry_src != NULL, this message is relayed, otherwise it is locally issued */
    834836
    835837        /* Get the routing data out of the message if any (in case of re-transmit) */
Note: See TracChangeset for help on using the changeset viewer.