peer.c

Go to the documentation of this file.
00001 
00055 #include <time.h>
00056 
00057 #include "peer.h"
00058 #include "diameter.h"
00059 
00068 peer* new_peer(str fqdn,str realm,int port)
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 }
00099 
00105 void free_peer(peer *x,int locked)
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 }
00115 
00120 inline void touch_peer(peer *p)
00121 {
00122     p->activity = time(0);
00123 }

Generated on Thu Oct 23 04:14:37 2008 for Open IMS Core CSCFs by  doxygen 1.5.2