[SR-Users] [Fwd: Re: Deleting the expired contacts using the Rtimer module]

kiran bhosale kbhosale at synteltelecom.com
Wed Feb 13 05:54:17 CET 2013


kiran bhosale wrote:
> he array values that  we are modifying and the function that  we  call 
> periodically  are   from our  module  . to exemplify i have put  the 
> code below .our requirement is that we want to delete the expired  
> contacts without  relying on usrloc module as "we  have  not used  any 
> DB for  contact  storage" but developed our own module for storing  
> them in a  file.even we  had installed  the  SIGALRM handler  in our  
> module for decrementing  the contacts  but the values of array (that 
> stores the expires) elements were zero. we thought  of workaround to 
> store  the expires values  to file  and  decrement them periodically. 
> but frequent  I/O  is very consuming. whats  the solution for deleting 
> the expired  contacts .
>
>
> #define DB_PATH "/usr/local/etc/kamailio/dbtext/syntel"
> #define DB_PATH1 "/usr/local/etc/kamailio/dbtext/temp"
> #define MAX_BUFFER 128
> #define MAX_USERS 128
> typedef struct
> {
> int max_bindings;
>  int  syntel_index;
>  int  expires[8];
> char ip_addr[8][16];
> } Syntel_users;
>
>
> Syntel_users syntel_database[16]={{0}};
>
>
>
> //this  is  function used for  storing the contacts
>
> int
> write_to_file (char *uri, char *user, int locator,int expires)
> {
> int Retval = 0;
> int fd;
> int bytes;
> char ip[13];
> strncpy (ip, &uri[9], 12);
> ip[12] = '\0';
> fd = open (DB_PATH, O_CREAT | O_RDWR | O_APPEND, 0777);
> if (syntel_database[locator].max_bindings < 8)
>   {
>     strcpy 
> (syntel_database[locator].ip_addr[syntel_database[locator].max_bindings], 
> uri);
>     
> syntel_database[locator].expires[syntel_database[locator].max_bindings]=expires; 
>
>     syntel_database[locator].max_bindings++;
>     bytes = write (fd, uri, strlen (uri));
>     Retval = 1;
>   }
> return Retval;
> }
>
> //AND THIS IS  FUNCTION WE CALL FROM  kamailio.conf WITH RTIMER MODULE 
> AFTER INTERVAL OF  1  SECOND.
>
>
> int syntel_delete (void)
> {
> int counter;
> int j;
> for (counter = 0; counter < 16; counter++)
>   {
>       for (j = 0; j < syntel_database[counter].max_bindings; j++)
>       {
>
>           if(syntel_database[counter].expires[j]<=0)
>           {
>                            
> memset(syntel_database[counter].ip_addr[j],0,strlen(syntel_database[counter].ip_addr[j])); 
>
>              syntel_database[counter].max_bindings--;
>           }
>           else
>           syntel_database[counter].expires[j]--;
>                 }
>
>   }
>   return 0;
> }
>
> BUT WHAT  THIS  FUNCTION GETS  IS  ZERO VALUES  FOR  EXPIRES AND NOT 
> MODIFIED IN  SYNTEL_WRITE_TO_FILE
>
>
> HOW  TO DECREMENT THESE VALUES PERIODICALLY THEN ??
>
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> Subject:
> Re: [SR-Users] Deleting the expired contacts using the Rtimer module
> From:
> kiran bhosale <kbhosale at synteltelecom.com>
> Date:
> Thu, 07 Feb 2013 10:30:39 +0530
> To:
> miconda at gmail.com
>
> To:
> miconda at gmail.com
>
>
> Daniel-Constantin Mierla wrote:
>> Hello,
>>
>> the static array is stored on the private memory per process, thus 
>> cannot be updated by the timer.
>>
>> You should allocate the array in shared memory at startup, then it 
>> should work to update it from different application processes. Be 
>> sure you synchronize (with locks/mutexes) the operations over the 
>> shared memory.
>>
>> Cheers,
>> Daniel
>>
>> On 2/6/13 7:53 AM, kiran bhosale wrote:
>>> Hi
>>>
>>> we  have  developed the custom module which stores the registered 
>>> users  in a file.now we are trying to remove the expired  contacts 
>>> using the rtimer module.while saving  the  registered users  to the 
>>> file  we also store the  expires  values in static  array.but when  
>>> we  try  to decrement the  these  values  in a function called  with 
>>> the help of rtimer  module. the values used  by this periodic  
>>> function are not modified ones but the initial which are zero. is it 
>>> that  we cant pass  the modified  values of  the global variables to 
>>> the timed  functions. to get around  this problem, we also 
>>> registered the timer in our module but got  same results !!!!!!!
>>>
>>>
>>> Please  Help.
>>>
>>> Thanks and regards .
>>>
>>> _______________________________________________
>>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
>>> sr-users at lists.sip-router.org
>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
>>
> the array values that  we are modifying and the function that  we  
> call periodically  are   from our  module  . to exemplify i have put  
> the code below .our requirement is that we want to delete the expired  
> contacts without  relying on usrloc module as "we  have  not used  any 
> DB for  contact  storage" but developed our own module for storing  
> them in a  file.even we  had installed  the  SIGALRM handler  in our  
> module for decrementing  the contacts  but the values of array (that 
> stores the expires) elements were zero. we thought  of workaround to 
> store  the expires values  to file  and  decrement them periodically. 
> but frequent  I/O  is very consuming. whats  the solution for deleting 
> the expired  contacts .
>
>
> #define DB_PATH "/usr/local/etc/kamailio/dbtext/syntel"
> #define DB_PATH1 "/usr/local/etc/kamailio/dbtext/temp"
> #define MAX_BUFFER 128
> #define MAX_USERS 128
> typedef struct
> {
>  int max_bindings;
>   int  syntel_index;
>   int  expires[8];
>  char ip_addr[8][16];
> } Syntel_users;
>
>
> Syntel_users syntel_database[16]={{0}};
>
>
>
> //this  is  function used for  storing the contacts
>
> int
> write_to_file (char *uri, char *user, int locator,int expires)
> {
>  int Retval = 0;
>  int fd;
>  int bytes;
>  char ip[13];
>  strncpy (ip, &uri[9], 12);
>  ip[12] = '\0';
>  fd = open (DB_PATH, O_CREAT | O_RDWR | O_APPEND, 0777);
>  if (syntel_database[locator].max_bindings < 8)
>    {
>      strcpy 
> (syntel_database[locator].ip_addr[syntel_database[locator].max_bindings], 
> uri);
>      
> syntel_database[locator].expires[syntel_database[locator].max_bindings]=expires; 
>
>      syntel_database[locator].max_bindings++;
>      bytes = write (fd, uri, strlen (uri));
>      Retval = 1;
>    }
>  return Retval;
> }
>
> //AND THIS IS  FUNCTION WE CALL FROM  kamailio.conf WITH RTIMER MODULE 
> AFTER INTERVAL OF  1  SECOND.
>
>
> int syntel_delete (void)
> {
>  int counter;
>  int j;
>  for (counter = 0; counter < 16; counter++)
>    {
>        for (j = 0; j < syntel_database[counter].max_bindings; j++)
>        {
>
>            if(syntel_database[counter].expires[j]<=0)
>            {
>                             
> memset(syntel_database[counter].ip_addr[j],0,strlen(syntel_database[counter].ip_addr[j])); 
>
>               syntel_database[counter].max_bindings--;
>            }
>            else
>            syntel_database[counter].expires[j]--;
>                  }
>  
>    }
>    return 0;
> }
>
> BUT WHAT  THIS  FUNCTION GETS  IS  ZERO VALUES  FOR  EXPIRES AND NOT 
> MODIFIED IN  SYNTEL_WRITE_TO_FILE
>
>
> HOW  TO DECREMENT THESE VALUES PERIODICALLY THEN ??
>
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
> sr-users at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
>   
thank you , we  managed all the data-structures in a  shared memory as u 
recommended and the problem got solved. thanks a lot  again




More information about the sr-users mailing list