Changeset 1014:908ffbb81f60 in freeDiameter for libfdcore
- Timestamp:
- Mar 29, 2013, 6:30:59 PM (11 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- libfdcore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdcore/fdcore-internal.h
r1010 r1014 134 134 pthread_mutex_t mtx; /* mutex to protect these lists */ 135 135 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) */ 137 137 }; 138 138 -
libfdcore/messages.c
r928 r1014 321 321 322 322 /* 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? */ ) ); 324 324 325 325 /* Post the message in the outgoing queue */ … … 330 330 331 331 /* 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 );332 int 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 ); 336 336 337 337 /* 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 ) ); 339 339 340 340 /* Post the message in the outgoing queue */ -
libfdcore/p_sr.c
r974 r1014 85 85 } 86 86 87 struct expire_data { 88 struct msg * request; 89 struct fd_peer * sentto; 90 }; 91 87 92 /* (detached) thread that calls the anscb on expired messages. 88 93 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 **);94 static void * call_expirecb(void * arg) { 95 struct expire_data * ed = arg; 96 97 void (*expirecb)(void *, DiamId_t, size_t, struct msg **); 93 98 void * data; 94 99 … … 103 108 104 109 /* Retrieve callback in the message */ 105 CHECK_FCT_DO( fd_msg_anscb_get( e xpired_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); 107 112 108 113 /* Clean up this data from the message */ 109 CHECK_FCT_DO( fd_msg_anscb_associate( e xpired_req, NULL, NULL, NULL ), return NULL);114 CHECK_FCT_DO( fd_msg_anscb_associate( ed->request, NULL, NULL, NULL, NULL ), return NULL); 110 115 111 116 /* 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); 113 118 114 119 /* 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); 119 126 120 127 /* Finish */ … … 125 132 static void * sr_expiry_th(void * arg) { 126 133 struct sr_list * srlist = arg; 127 struct msg * expired_req;128 134 pthread_attr_t detached; 135 struct expire_data * ed; 129 136 130 137 TRACE_ENTRY("%p", arg); … … 177 184 178 185 /* 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; 179 189 fd_list_unlink(&first->chain); 180 190 fd_list_unlink(&first->expire); 181 expired_req = first->req;182 191 free(first); 183 192 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 ); 185 194 186 195 /* loop */ -
libfdcore/routing_dispatch.c
r974 r1014 467 467 468 468 /* 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 ) ); 470 470 471 471 /* If a callback was registered, pass the message to it */ … … 793 793 struct rtd_candidate * c; 794 794 struct msg *msgptr = msg; 795 DiamId_t qry_src = NULL; 796 size_t qry_src_len = 0; 795 797 796 798 /* Read the message header */ … … 801 803 if ( ! is_req ) { 802 804 struct msg * qry; 803 DiamId_t qry_src = NULL;804 size_t qry_src_len = 0;805 805 struct msg_hdr * qry_hdr; 806 806 struct fd_peer * peer = NULL; … … 832 832 833 833 /* 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 */ 834 836 835 837 /* 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.