Mercurial > hg > freeDiameter
comparison libfdproto/messages.c @ 1014:908ffbb81f60
Added a second callback in fd_msg_send_timeout to handle more easily the timeout situation
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Fri, 29 Mar 2013 17:30:59 +0800 |
parents | e22434c66126 |
children | 0117a7746b21 |
comparison
equal
deleted
inserted
replaced
1013:7b5c46505e09 | 1014:908ffbb81f60 |
---|---|
119 struct msg *msg_query; /* the associated query if the message is a received answer */ | 119 struct msg *msg_query; /* the associated query if the message is a received answer */ |
120 int msg_associated; /* and the counter part information in the query, to avoid double free */ | 120 int msg_associated; /* and the counter part information in the query, to avoid double free */ |
121 struct rt_data *msg_rtdata; /* Routing list for the query */ | 121 struct rt_data *msg_rtdata; /* Routing list for the query */ |
122 struct session *msg_sess; /* Cached message session if any */ | 122 struct session *msg_sess; /* Cached message session if any */ |
123 struct { | 123 struct { |
124 void (*fct)(void *, struct msg **); | 124 void (*anscb)(void *, struct msg **); |
125 void (*expirecb)(void *, DiamId_t, size_t, struct msg **); | |
125 void * data; | 126 void * data; |
126 struct timespec timeout; | 127 struct timespec timeout; |
127 } msg_cb; /* Callback to be called when an answer is received, if not NULL */ | 128 } msg_cb; /* Callback to be called when an answer is received, or timeout expires, if not NULL */ |
128 DiamId_t msg_src_id; /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */ | 129 DiamId_t msg_src_id; /* Diameter Id of the peer this message was received from. This string is malloc'd and must be freed */ |
129 size_t msg_src_id_len; /* cached length of this string */ | 130 size_t msg_src_id_len; /* cached length of this string */ |
130 struct timespec msg_ts_rcv; /* Timestamp when this message was received from the network */ | 131 struct timespec msg_ts_rcv; /* Timestamp when this message was received from the network */ |
131 struct timespec msg_ts_sent; /* Timestamp when this message was sent to the network */ | 132 struct timespec msg_ts_sent; /* Timestamp when this message was sent to the network */ |
132 | 133 |
772 msg->msg_public.msg_code, | 773 msg->msg_public.msg_code, |
773 msg->msg_public.msg_appl, | 774 msg->msg_public.msg_appl, |
774 msg->msg_public.msg_hbhid, | 775 msg->msg_public.msg_hbhid, |
775 msg->msg_public.msg_eteid | 776 msg->msg_public.msg_eteid |
776 ) ); | 777 ) ); |
777 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "intern: rwb:%p rt:%d cb:%p(%p) qry:%p asso:%d sess:%p src:%s(%zd)|", | 778 CHECK_FCT( dump_add_str(outstr, offset, outlen, INOBJHDR "intern: rwb:%p rt:%d cb:%p,%p(%p) qry:%p asso:%d sess:%p src:%s(%zd)|", |
778 INOBJHDRVAL, msg->msg_rawbuffer, msg->msg_routable, msg->msg_cb.fct, msg->msg_cb.data, msg->msg_query, msg->msg_associated, msg->msg_sess, msg->msg_src_id?:"(nil)", msg->msg_src_id_len) ); | 779 INOBJHDRVAL, msg->msg_rawbuffer, msg->msg_routable, msg->msg_cb.anscb, msg->msg_cb.expirecb, msg->msg_cb.data, msg->msg_query, msg->msg_associated, msg->msg_sess, msg->msg_src_id?:"(nil)", msg->msg_src_id_len) ); |
779 return 0; | 780 return 0; |
780 } | 781 } |
781 | 782 |
782 /* Dump an avp object */ | 783 /* Dump an avp object */ |
783 static int obj_dump_avp ( struct avp * avp, int indent, char **outstr, size_t *offset, size_t *outlen ) | 784 static int obj_dump_avp ( struct avp * avp, int indent, char **outstr, size_t *offset, size_t *outlen ) |
1027 | 1028 |
1028 return 0; | 1029 return 0; |
1029 } | 1030 } |
1030 | 1031 |
1031 /* Associate / get answer callbacks */ | 1032 /* Associate / get answer callbacks */ |
1032 int fd_msg_anscb_associate( struct msg * msg, void ( *anscb)(void *, struct msg **), void * data, const struct timespec *timeout ) | 1033 int 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 ) |
1033 { | 1034 { |
1034 TRACE_ENTRY("%p %p %p", msg, anscb, data); | 1035 TRACE_ENTRY("%p %p %p %p", msg, anscb, expirecb, data); |
1035 | 1036 |
1036 /* Check the parameters */ | 1037 /* Check the parameters */ |
1037 CHECK_PARAMS( CHECK_MSG(msg) ); | 1038 CHECK_PARAMS( CHECK_MSG(msg) ); |
1038 | 1039 |
1039 if (! (msg->msg_public.msg_flags & CMD_FLAG_REQUEST )) | 1040 if (! (msg->msg_public.msg_flags & CMD_FLAG_REQUEST )) |
1040 return anscb ? EINVAL : 0; /* we associate with requests only */ | 1041 return anscb ? EINVAL : 0; /* we associate with requests only */ |
1041 | 1042 |
1042 CHECK_PARAMS( (anscb == NULL) || (msg->msg_cb.fct == NULL) ); /* We are not overwritting a cb */ | 1043 CHECK_PARAMS( (anscb == NULL) || (msg->msg_cb.anscb == NULL) ); /* We are not overwritting a cb */ |
1044 CHECK_PARAMS( (expirecb == NULL) || (msg->msg_cb.expirecb == NULL) ); /* We are not overwritting a cb */ | |
1043 | 1045 |
1044 /* Associate callback and data with the message, if any */ | 1046 /* Associate callback and data with the message, if any */ |
1045 msg->msg_cb.fct = anscb; | 1047 msg->msg_cb.anscb = anscb; |
1048 msg->msg_cb.expirecb = expirecb; | |
1046 msg->msg_cb.data = data; | 1049 msg->msg_cb.data = data; |
1047 if (timeout) { | 1050 if (timeout) { |
1048 memcpy(&msg->msg_cb.timeout, timeout, sizeof(struct timespec)); | 1051 memcpy(&msg->msg_cb.timeout, timeout, sizeof(struct timespec)); |
1049 } | 1052 } |
1050 | 1053 |
1051 return 0; | 1054 return 0; |
1052 } | 1055 } |
1053 | 1056 |
1054 int fd_msg_anscb_get( struct msg * msg, void (**anscb)(void *, struct msg **), void ** data ) | 1057 int fd_msg_anscb_get( struct msg * msg, void (**anscb)(void *, struct msg **), void (**expirecb)(void *, DiamId_t, size_t, struct msg **), void ** data ) |
1055 { | 1058 { |
1056 TRACE_ENTRY("%p %p %p", msg, anscb, data); | 1059 TRACE_ENTRY("%p %p %p %p", msg, anscb, expirecb, data); |
1057 | 1060 |
1058 /* Check the parameters */ | 1061 /* Check the parameters */ |
1059 CHECK_PARAMS( CHECK_MSG(msg) && anscb && data ); | 1062 CHECK_PARAMS( CHECK_MSG(msg) ); |
1060 | 1063 |
1061 /* Copy the result */ | 1064 /* Copy the result */ |
1062 *anscb = msg->msg_cb.fct; | 1065 if (anscb) |
1063 *data = msg->msg_cb.data; | 1066 *anscb = msg->msg_cb.anscb; |
1067 if (data) | |
1068 *data = msg->msg_cb.data; | |
1069 if (expirecb) | |
1070 *expirecb = msg->msg_cb.expirecb; | |
1064 | 1071 |
1065 return 0; | 1072 return 0; |
1066 } | 1073 } |
1067 | 1074 |
1068 struct timespec *fd_msg_anscb_gettimeout( struct msg * msg ) | 1075 struct timespec *fd_msg_anscb_gettimeout( struct msg * msg ) |