Definition in file transaction.h.
#include <time.h>
#include "utils.h"
#include "diameter.h"
#include "diameter_api.h"
Go to the source code of this file.
Data Structures | |
| struct | _cdp_trans_t |
| Diameter Transaction representation. More... | |
| struct | cdp_trans_list_t |
| Diameter Transaction list. More... | |
Typedefs | |
| typedef _cdp_trans_t | cdp_trans_t |
| Diameter Transaction representation. | |
Functions | |
| int | trans_init () |
| Initializes the transaction structure. | |
| cdp_trans_t * | add_trans (AAAMessage *msg, AAATransactionCallback_f *cb, void *ptr, int timeout, int auto_drop) |
| Create and add a transaction to the transaction list. | |
| void | del_trans (AAAMessage *msg) |
| Remove from the list and deallocate a transaction. | |
| cdp_trans_t * | take_trans (AAAMessage *msg) |
| Return and remove the transaction from the transaction list. | |
| void | free_trans (cdp_trans_t *x) |
| Deallocate the memory taken by a transaction. | |
| void | trans_timer (time_t now, void *ptr) |
| Timer callback for checking the transaction status. | |
| typedef struct _cdp_trans_t cdp_trans_t |
Diameter Transaction representation.
| int trans_init | ( | ) |
Initializes the transaction structure.
Also adds a timer callback for checking the transaction statuses
Definition at line 69 of file transaction.c.
References add_timer(), cdp_trans_list_t::head, cdp_trans_list_t::lock, LOG_NO_MEM, cdp_trans_list_t::tail, trans_list, and trans_timer().
Referenced by diameter_peer_init().
00070 { 00071 trans_list = shm_malloc(sizeof(cdp_trans_list_t)); 00072 if (!trans_list){ 00073 LOG_NO_MEM("shm",sizeof(cdp_trans_list_t)); 00074 return 0; 00075 } 00076 trans_list->head = 0; 00077 trans_list->tail = 0; 00078 trans_list->lock = lock_alloc(); 00079 trans_list->lock = lock_init(trans_list->lock); 00080 00081 add_timer(1,0,trans_timer,0); 00082 return 1; 00083 }
| cdp_trans_t* add_trans | ( | AAAMessage * | msg, | |
| AAATransactionCallback_f * | cb, | |||
| void * | ptr, | |||
| int | timeout, | |||
| int | auto_drop | |||
| ) | [inline] |
Create and add a transaction to the transaction list.
| msg | - the message that this related to | |
| cb | - callback to be called on response or time-out | |
| ptr | - generic pointer to pass to the callback on call | |
| timeout | - timeout time in seconds | |
| auto_drop | - whether to auto drop the transaction on event, or let the application do it later |
Definition at line 94 of file transaction.c.
References _cdp_trans_t::auto_drop, _cdp_trans_t::cb, _message_t::endtoendId, _cdp_trans_t::endtoendid, _cdp_trans_t::expires, cdp_trans_list_t::head, _message_t::hopbyhopId, _cdp_trans_t::hopbyhopid, cdp_trans_list_t::lock, LOG_NO_MEM, _cdp_trans_t::next, _cdp_trans_t::prev, _cdp_trans_t::ptr, cdp_trans_list_t::tail, and trans_list.
Referenced by AAASendMessage(), AAASendMessageToPeer(), AAASendRecvMessage(), and AAASendRecvMessageToPeer().
00095 { 00096 cdp_trans_t *x; 00097 x = shm_malloc(sizeof(cdp_trans_t)); 00098 if (!x) { 00099 LOG_NO_MEM("shm",sizeof(cdp_trans_t)); 00100 return 0; 00101 } 00102 x->ptr = shm_malloc(sizeof(void*)); 00103 if (!x->ptr) { 00104 LOG_NO_MEM("shm",sizeof(void*)); 00105 shm_free(x); 00106 return 0; 00107 } 00108 x->endtoendid = msg->endtoendId; 00109 x->hopbyhopid = msg->hopbyhopId; 00110 x->cb = cb; 00111 *(x->ptr) = ptr; 00112 x->expires = timeout + time(0); 00113 x->auto_drop = auto_drop; 00114 x->next = 0; 00115 00116 lock_get(trans_list->lock); 00117 x->prev = trans_list->tail; 00118 if (trans_list->tail) trans_list->tail->next = x; 00119 trans_list->tail = x; 00120 if (!trans_list->head) trans_list->head = x; 00121 lock_release(trans_list->lock); 00122 return x; 00123 }
| void del_trans | ( | AAAMessage * | msg | ) | [inline] |
Remove from the list and deallocate a transaction.
| msg | - the message that relates to that particular transaction |
Definition at line 129 of file transaction.c.
References _message_t::endtoendId, _cdp_trans_t::endtoendid, free_trans(), cdp_trans_list_t::head, _message_t::hopbyhopId, _cdp_trans_t::hopbyhopid, cdp_trans_list_t::lock, _cdp_trans_t::next, _cdp_trans_t::prev, cdp_trans_list_t::tail, and trans_list.
00130 { 00131 cdp_trans_t *x; 00132 lock_get(trans_list->lock); 00133 x = trans_list->head; 00134 while(x&& x->endtoendid!=msg->endtoendId && x->hopbyhopid!=msg->hopbyhopId) x = x->next; 00135 if (x){ 00136 if (x->prev) x->prev->next = x->next; 00137 else trans_list->head = x->next; 00138 if (x->next) x->next->prev = x->prev; 00139 else trans_list->tail = x->prev; 00140 free_trans(x); 00141 } 00142 lock_release(trans_list->lock); 00143 }
| cdp_trans_t* take_trans | ( | AAAMessage * | msg | ) | [inline] |
Return and remove the transaction from the transaction list.
| msg | - the message that this transaction relates to |
Definition at line 150 of file transaction.c.
References _message_t::endtoendId, _cdp_trans_t::endtoendid, cdp_trans_list_t::head, _message_t::hopbyhopId, _cdp_trans_t::hopbyhopid, cdp_trans_list_t::lock, _cdp_trans_t::next, _cdp_trans_t::prev, cdp_trans_list_t::tail, and trans_list.
Referenced by api_callback().
00151 { 00152 cdp_trans_t *x; 00153 lock_get(trans_list->lock); 00154 x = trans_list->head; 00155 while(x&& x->endtoendid!=msg->endtoendId && x->hopbyhopid!=msg->hopbyhopId) x = x->next; 00156 if (x){ 00157 if (x->prev) x->prev->next = x->next; 00158 else trans_list->head = x->next; 00159 if (x->next) x->next->prev = x->prev; 00160 else trans_list->tail = x->prev; 00161 } 00162 lock_release(trans_list->lock); 00163 return x; 00164 }
| void free_trans | ( | cdp_trans_t * | x | ) | [inline] |
Deallocate the memory taken by a transaction.
| x | - the transaction to deallocate |
Definition at line 170 of file transaction.c.
References _cdp_trans_t::ptr.
Referenced by AAASendRecvMessage(), AAASendRecvMessageToPeer(), api_callback(), del_trans(), and trans_timer().
| void trans_timer | ( | time_t | now, | |
| void * | ptr | |||
| ) |
Timer callback for checking the transaction status.
| now | - time of call | |
| ptr | - generic pointer, passed to the transactional callbacks |
Definition at line 181 of file transaction.c.
References _cdp_trans_t::ans, _cdp_trans_t::auto_drop, _cdp_trans_t::cb, _cdp_trans_t::expires, free_trans(), cdp_trans_list_t::head, cdp_trans_list_t::lock, _cdp_trans_t::next, _cdp_trans_t::prev, _cdp_trans_t::ptr, cdp_trans_list_t::tail, and trans_list.
Referenced by trans_init().
00182 { 00183 cdp_trans_t *x,*n; 00184 LOG(L_DBG,"DBG:trans_timer(): taking care of diameter transactions...\n"); 00185 lock_get(trans_list->lock); 00186 x = trans_list->head; 00187 while(x) 00188 { 00189 if (now>x->expires){ 00190 x->ans = 0; 00191 if (x->cb){ 00192 (x->cb)(1,*(x->ptr),0); 00193 } 00194 n = x->next; 00195 00196 if (x->prev) x->prev->next = x->next; 00197 else trans_list->head = x->next; 00198 if (x->next) x->next->prev = x->prev; 00199 else trans_list->tail = x->prev; 00200 if (x->auto_drop) free_trans(x); 00201 00202 x = n; 00203 } else 00204 x = x->next; 00205 } 00206 lock_release(trans_list->lock); 00207 }
1.5.2