Navigation


Changeset 1014:908ffbb81f60 in freeDiameter for include


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:
include/freeDiameter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/freeDiameter/libfdcore.h

    r1010 r1014  
    463463 * PARAMETERS:
    464464 *  pmsg        : Location of the message to be sent on the network (set to NULL on function return to avoid double deletion).
    465  *  anscb       : A callback to be called when answer is received, if msg is a request (optional for fd_msg_send)
    466  *  anscb_data  : opaque data to be passed back to the anscb when it is called.
     465 *  anscb       : A callback to be called when corresponding answer is received, when sending a request (not used with answers)
     466 *  anscb_data  : opaque data to be passed back to the anscb (or expirecb) when it is called.
     467 *  expirecb    : (only for fd_msg_send_timeout) If the request did not get an answer before timeout, this callback is called.
    467468 *  timeout     : (only for fd_msg_send_timeout) sets the absolute time until when to wait for an answer. Past this time,
    468  *                the anscb is called with the request as parameter and the answer will be discarded when received.
     469 *                the expirecb is called with the request and the answer will be discarded if received later.
    469470 *
    470471 * DESCRIPTION:
    471472 *   Sends a message on the network. (actually simply queues it in a global queue, to be picked by a daemon's thread)
    472473 * For requests, the end-to-end id must be set (see fd_msg_get_eteid / MSGFL_ALLOC_ETEID).
    473  * For answers, the message must be created with function fd_msg_new_answ.
     474 * For answers, the message must be created with function fd_msg_new_answer_from_req.
    474475 *
    475476 * The routing module will handle sending to the correct peer, usually based on the Destination-Realm / Destination-Host AVP.
     
    477478 * If the msg is a request, there are two ways of receiving the answer:
    478479 *  - either having registered a callback in the dispatch module (see fd_disp_register)
    479  *  - or provide a callback as parameter here. If such callback is provided, it is called before the dispatch callbacks.
    480  *    The prototype for this callback function is:
     480 *  - or provide a anscb callback here. If such callback is provided, it is called before the dispatch callbacks.
     481 *    The prototype for this anscb callback function is:
    481482 *     void anscb(void * data, struct msg ** answer)
    482483 *      where:
     
    489490 * If no callback is registered to handle an answer, the message is discarded and an error is logged.
    490491 *
    491  *  fd_msg_send_timeout is similar to fd_msg_send, except that it takes an additional argument "timeout" and can be called
    492  * only with requests as parameters, and an anscb callback.
    493  * If the matching answer or error is received before the timeout date passes, everything occurs as with fd_msg_send. Otherwise,
    494  * the request is removed from the queue (meaning the matching answer will be discarded upon reception) and passed to the answcb
    495  * function. This function can easily distinguish between timeout case and answer case by checking if the message received is
    496  * a request. Upon return, if the *msg parameter is not NULL, it is freed (not passed to other callbacks).
     492 *  fd_msg_send_timeout is similar to fd_msg_send, except that it takes two additional arguments "expirecb" and "timeout".
     493 * If the message parameter is an answer, there is no difference with fd_msg_send.
     494 * Otherwise, if the corresponding answer (or error) is received before the timeout date elapses, everything occurs as with fd_msg_send.
     495 * Otherwise, the request is removed from the queue (meaning the matching answer will be discarded upon reception) and passed to the expirecb
     496 * function. Upon return, if the *msg parameter is not NULL, it is freed (not passed to other callbacks).
     497 * expirecb is called in a dedicated thread.
     498 *
     499 *    The prototype for the expirecb callback function is:
     500 *     void expirecb(void * data, struct peer_hdr * sentto, struct msg ** request)
     501 *      where:
     502 *              data   : opaque data that was registered along with the callback.
     503 *              sentto : pointer to the peer to which the message was sent and no answer received within timeout.
     504 *              request: location of the pointer to the request that was not answered.
    497505 *
    498506 * RETURN VALUE:
     
    502510 */
    503511int fd_msg_send ( struct msg ** pmsg, void (*anscb)(void *, struct msg **), void * data );
    504 int fd_msg_send_timeout ( struct msg ** pmsg, void (*anscb)(void *, struct msg **), void * data, const struct timespec *timeout );
     512int 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 );
    505513
    506514/*
  • include/freeDiameter/libfdproto.h

    r1004 r1014  
    24272427 *
    24282428 * PARAMETERS:
    2429  *  msg         : the answer message
     2429 *  msg         : the request message
    24302430 *  anscb       : the callback to associate with the message
    24312431 *  data        : the data to pass to the callback
     2432 *  expirecb    : the expiration callback to associate with the message
    24322433 *  timeout     : (optional, use NULL if no timeout) a timeout associated with calling the cb.
    24332434 *
    24342435 * DESCRIPTION:
    2435  *  Associate or retrieve a callback with an answer message.
     2436 *  Associate or retrieve callbacks with an message.
    24362437 * This is meant to be called from the daemon only.
    24372438 *
     
    24402441 *  EINVAL: a parameter is invalid
    24412442 */
    2442 int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void  * data, const struct timespec *timeout );
    2443 int fd_msg_anscb_get      ( struct msg * msg, void (**anscb)(void *, struct msg **), void ** data );
     2443int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void  * data, void (*expirecb)(void *, DiamId_t, size_t, struct msg **), const struct timespec *timeout );
     2444int fd_msg_anscb_get( struct msg * msg, void (**anscb)(void *, struct msg **), void (**expirecb)(void *, DiamId_t, size_t, struct msg **), void ** data );
    24442445struct timespec *fd_msg_anscb_gettimeout( struct msg * msg ); /* returns NULL or a valid non-0 timespec */
    24452446
Note: See TracChangeset for help on using the changeset viewer.