[SR-Users] [Fwd: Re: Deleting the expired contacts using the Rtimer module]
Daniel-Constantin Mierla
miconda at gmail.com
Fri Feb 8 10:24:07 CET 2013
The problem is that you declare the array in the private space of each
process.
Kamailio is a multi process application, a running instance starting
several processes. Because you want to work on the same array from
different processes, you must allocate that array in shared memory:
When your module is initialized, you have to use shm_malloc()... to
allocate the array. Some details about memory manager functions in
kamailio at:
- http://www.asipto.com/pub/kamailio-devel-guide/#c04memory
Also, you have to use locks to access the array, because many processes
can try to read/write from same location, due to parallel processing.
Cheers,
Daniel
On 2/7/13 6:05 AM, 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 ??
>
>
>
>
>
>
>
>
> _______________________________________________
> 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
--
Daniel-Constantin Mierla - http://www.asipto.com
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Kamailio World Conference, April 16-17, 2013, Berlin
- http://conference.kamailio.com -
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20130208/8599f6b7/attachment-0001.htm>
More information about the sr-users
mailing list