Changeset 646:cfc8da9264f4 in freeDiameter
- Timestamp:
- Jan 4, 2011, 4:20:50 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/messages.c
r116 r646 269 269 /* Save the callback in the message */ 270 270 if (anscb) { 271 CHECK_FCT( fd_msg_anscb_associate( *pmsg, anscb, data ) );271 CHECK_FCT( fd_msg_anscb_associate( *pmsg, anscb, data, NULL /* we should maybe use a safeguard here like 1 hour or so? */ ) ); 272 272 } 273 273 … … 277 277 return 0; 278 278 } 279 280 /* The variation of the same function with a timeout callback */ 281 int fd_msg_send_timeout ( struct msg ** pmsg, void (*anscb)(void *, struct msg **), void * data, const struct timespec *timeout ) 282 { 283 TRACE_ENTRY("%p %p %p", pmsg, anscb, data, timeout); 284 CHECK_PARAMS( pmsg && anscb && timeout ); 285 286 /* Save the callback in the message, with the timeout */ 287 CHECK_FCT( fd_msg_anscb_associate( *pmsg, anscb, data, timeout ) ); 288 289 /* Post the message in the outgoing queue */ 290 CHECK_FCT( fd_fifo_post(fd_g_outgoing, pmsg) ); 291 292 return 0; 293 } 294 279 295 280 296 /* Parse a message against our dictionary, and in case of error log and eventually build the error reply -- returns the parsing status */ -
include/freeDiameter/freeDiameter.h
r640 r646 371 371 372 372 /* 373 * FUNCTION: fd_msg_send 373 * FUNCTION: fd_msg_send, fd_msg_send_timeout 374 374 * 375 375 * PARAMETERS: 376 376 * pmsg : Location of the message to be sent on the network (set to NULL on function return to avoid double deletion). 377 * anscb : A callback to be called when answer is received, if msg is a request (optional )377 * anscb : A callback to be called when answer is received, if msg is a request (optional for fd_msg_send) 378 378 * anscb_data : opaque data to be passed back to the anscb when it is called. 379 * timeout : (only for fd_msg_send_timeout) sets the absolute time until when to wait for an answer. Past this time, 380 * the anscb is called with the request as parameter and the answer will be discarded when received. 379 381 * 380 382 * DESCRIPTION: … … 399 401 * If no callback is registered to handle an answer, the message is discarded and an error is logged. 400 402 * 403 * fd_msg_send_timeout is similar to fd_msg_send, except that it takes an additional argument "timeout" and can be called 404 * only with requests as parameters, and an anscb callback. 405 * If the matching answer or error is received before the timeout date passes, everything occurs as with fd_msg_send. Otherwise, 406 * the request is removed from the queue (meaning the matching answer will be discarded upon reception) and passed to the answcb 407 * function. This function can easily distinguish between timeout case and answer case by checking if the message received is 408 * a request. Upon return, if the *msg parameter is not NULL, it is freed (not passed to other callbacks). 409 * 401 410 * RETURN VALUE: 402 411 * 0 : The message has been queued for sending (sending may fail asynchronously). … … 405 414 */ 406 415 int fd_msg_send ( struct msg ** pmsg, void (*anscb)(void *, struct msg **), void * data ); 416 int fd_msg_send_timeout ( struct msg ** pmsg, void (*anscb)(void *, struct msg **), void * data, const struct timespec *timeout ); 407 417 408 418 /* -
include/freeDiameter/libfreeDiameter.h
r639 r646 2135 2135 * anscb : the callback to associate with the message 2136 2136 * data : the data to pass to the callback 2137 * timeout : (optional, use NULL if no timeout) a timeout associated with calling the cb. 2137 2138 * 2138 2139 * DESCRIPTION: … … 2144 2145 * EINVAL: a parameter is invalid 2145 2146 */ 2146 int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void * data );2147 int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void * data, const struct timespec *timeout ); 2147 2148 int fd_msg_anscb_get ( struct msg * msg, void (**anscb)(void *, struct msg **), void ** data ); 2148 2149 -
libfreeDiameter/messages.c
r638 r646 124 124 void (*fct)(void *, struct msg **); 125 125 void * data; 126 struct timespec timeout; 126 127 } msg_cb; /* Callback to be called when an answer is received, if not NULL */ 127 128 char * msg_src_id; /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */ … … 904 905 905 906 /* Associate / get answer callbacks */ 906 int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void * data )907 int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void * data, const struct timespec *timeout ) 907 908 { 908 909 TRACE_ENTRY("%p %p %p", msg, anscb, data); … … 916 917 msg->msg_cb.fct = anscb; 917 918 msg->msg_cb.data = data; 919 if (timeout) { 920 memcpy(&msg->msg_cb.timeout, timeout, sizeof(struct timespec)); 921 } else { 922 memset(&msg->msg_cb.timeout, 0, sizeof(struct timespec)); /* clear the area */ 923 } 918 924 919 925 return 0;
Note: See TracChangeset
for help on using the changeset viewer.