Navigation


Changeset 646:cfc8da9264f4 in freeDiameter


Ignore:
Timestamp:
Jan 4, 2011, 4:20:50 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Prepared first part of the changes for #10

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/messages.c

    r116 r646  
    269269        /* Save the callback in the message */
    270270        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? */ )  );
    272272        }
    273273       
     
    277277        return 0;
    278278}
     279
     280/* The variation of the same function with a timeout callback */
     281int 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
    279295
    280296/* 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  
    371371
    372372/*
    373  * FUNCTION:    fd_msg_send
     373 * FUNCTION:    fd_msg_send, fd_msg_send_timeout 
    374374 *
    375375 * PARAMETERS:
    376376 *  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)
    378378 *  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.
    379381 *
    380382 * DESCRIPTION:
     
    399401 * If no callback is registered to handle an answer, the message is discarded and an error is logged.
    400402 *
     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 *
    401410 * RETURN VALUE:
    402411 *  0           : The message has been queued for sending (sending may fail asynchronously).
     
    405414 */
    406415int fd_msg_send ( struct msg ** pmsg, void (*anscb)(void *, struct msg **), void * data );
     416int fd_msg_send_timeout ( struct msg ** pmsg, void (*anscb)(void *, struct msg **), void * data, const struct timespec *timeout );
    407417
    408418/*
  • include/freeDiameter/libfreeDiameter.h

    r639 r646  
    21352135 *  anscb       : the callback to associate with the message
    21362136 *  data        : the data to pass to the callback
     2137 *  timeout     : (optional, use NULL if no timeout) a timeout associated with calling the cb.
    21372138 *
    21382139 * DESCRIPTION:
     
    21442145 *  EINVAL: a parameter is invalid
    21452146 */
    2146 int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void  * data );
     2147int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void  * data, const struct timespec *timeout );
    21472148int fd_msg_anscb_get      ( struct msg * msg, void (**anscb)(void *, struct msg **), void ** data );
    21482149
  • libfreeDiameter/messages.c

    r638 r646  
    124124                        void (*fct)(void *, struct msg **);
    125125                        void * data;
     126                        struct timespec timeout;
    126127                }                msg_cb;                /* Callback to be called when an answer is received, if not NULL */
    127128        char *                   msg_src_id;            /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */
     
    904905
    905906/* Associate / get answer callbacks */
    906 int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void  * data )
     907int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void  * data, const struct timespec *timeout )
    907908{
    908909        TRACE_ENTRY("%p %p %p", msg, anscb, data);
     
    916917        msg->msg_cb.fct = anscb;
    917918        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        }
    918924       
    919925        return 0;
Note: See TracChangeset for help on using the changeset viewer.