Navigation


Changeset 1014:908ffbb81f60 in freeDiameter for libfdcore/p_sr.c


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 */
Note: See TracChangeset for help on using the changeset viewer.