Definition in file peer.c.
#include <time.h>
#include "peer.h"
#include "diameter.h"
Go to the source code of this file.
Functions | |
| peer * | new_peer (str fqdn, str realm, int port) |
| Create a new peer. | |
| void | free_peer (peer *x, int locked) |
| Frees the memory taken by a peer structure. | |
| void | touch_peer (peer *p) |
| "Touches" the peer by updating the last activity time to the current time. | |
| peer* new_peer | ( | str | fqdn, | |
| str | realm, | |||
| int | port | |||
| ) |
Create a new peer.
| fqdn | - FQDN of the peer | |
| realm | - Realm of the peer | |
| port | - port of the peer to connect to |
Definition at line 68 of file peer.c.
References _peer_t::activity, Closed, _peer_t::fqdn, _peer_t::I_sock, _peer_t::lock, LOG_NO_MEM, _peer_t::next, _peer_t::port, _peer_t::prev, _peer_t::R_sock, _peer_t::realm, shm_str_dup, and _peer_t::state.
Referenced by get_peer_from_fqdn(), and peer_manager_init().
00069 { 00070 peer *x; 00071 x = shm_malloc(sizeof(peer)); 00072 if (!x){ 00073 LOG_NO_MEM("shm",sizeof(peer)); 00074 goto error; 00075 } 00076 memset(x,0,sizeof(peer)); 00077 shm_str_dup(x->fqdn,fqdn); 00078 if (!x->fqdn.s) goto error; 00079 shm_str_dup(x->realm,realm); 00080 if (!x->realm.s) goto error; 00081 x->port = port; 00082 x->lock = lock_alloc(); 00083 x->lock = lock_init(x->lock); 00084 00085 x->state = Closed; 00086 00087 x->I_sock = -1; 00088 x->R_sock = -1; 00089 00090 x->activity = time(0)-500; 00091 00092 x->next = 0; 00093 x->prev = 0; 00094 00095 return x; 00096 error: 00097 return 0; 00098 }
| void free_peer | ( | peer * | x, | |
| int | locked | |||
| ) |
Frees the memory taken by a peer structure.
| x | - the peer to free | |
| locked | - if the caller of this function already acquired the lock on this peer |
Definition at line 105 of file peer.c.
References _peer_t::fqdn, _peer_t::lock, and _peer_t::realm.
Referenced by peer_manager_destroy(), and peer_timer().
00106 { 00107 if (!x) return; 00108 if (!locked) lock_get(x->lock); 00109 if (x->fqdn.s) shm_free(x->fqdn.s); 00110 if (x->realm.s) shm_free(x->realm.s); 00111 lock_destroy(x->lock); 00112 lock_dealloc((void*)x->lock); 00113 shm_free(x); 00114 }
| void touch_peer | ( | peer * | p | ) | [inline] |
"Touches" the peer by updating the last activity time to the current time.
| p | - which peer to touch |
Definition at line 120 of file peer.c.
References _peer_t::activity.
Referenced by get_peer_from_fqdn(), peer_timer(), R_Accept(), receive_message(), and Snd_Message().
00121 { 00122 p->activity = time(0); 00123 }
1.5.2