You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by ricardo13 <ri...@gmail.com> on 2008/11/18 20:17:26 UTC
APR, Shared Memory and extern process
Hi,
I'm writing a apache's module that comunicate with a extern process.
My extern process is built in C:
char* shm_address;
int shmid;
key_t shmkey;
shmkey = 5678;
shmid = shmget(shmkey, SIZEOFSHMSEG, 0666);
if (shmid == -1)
printf("main: shmget() failed\n");
shm_address = shmat(shmid, NULL, 0);
if ( shm_address==NULL )
printf("main: shmat() failed\n");
while(1) {
if(strcmp(shm_address, ":") == 0) {
strcpy(shm_address, data);
break;
}
}
int rc = shmdt(shm_address);
if (rc==-1)
printf("main: shmdt() failed\n");
Now I want to write a module that take (or get) the information in this
segment.
Can someone help me ??
Thank You
Ricardo
--
View this message in context: http://www.nabble.com/APR%2C-Shared-Memory-and-extern-process-tp20566322p20566322.html
Sent from the Apache HTTP Server - Module Writers mailing list archive at Nabble.com.
Re: APR, Shared Memory and extern process
Posted by ricardo13 <ri...@gmail.com>.
Sorin Manolache wrote:
>
> On Tue, Nov 18, 2008 at 20:17, ricardo13 <ri...@gmail.com> wrote:
>>
>> Hi,
>>
>> I'm writing a apache's module that comunicate with a extern process.
>>
>> My extern process is built in C:
>>
>> char* shm_address;
>> int shmid;
>> key_t shmkey;
>>
>> shmkey = 5678;
>> shmid = shmget(shmkey, SIZEOFSHMSEG, 0666);
>> if (shmid == -1)
>> printf("main: shmget() failed\n");
>>
>> shm_address = shmat(shmid, NULL, 0);
>> if ( shm_address==NULL )
>> printf("main: shmat() failed\n");
>>
>> while(1) {
>> if(strcmp(shm_address, ":") == 0) {
>> strcpy(shm_address, data);
>> break;
>> }
>> }
>>
>> int rc = shmdt(shm_address);
>> if (rc==-1)
>> printf("main: shmdt() failed\n");
>>
>>
>> Now I want to write a module that take (or get) the information in this
>> segment.
>> Can someone help me ??
>>
>> Thank You
>>
>> Ricardo
>
> Use the post_config hook because it is run in the parent of all apache
> children. There, you simply shmget and shmat. Also, use
> apr_pool_register_cleanup in order to register a callback that will
> shmdt your shared memory segment when the config pool is destroyed,
> i.e. when apache is killed or the configuration reloaded.
>
> I'm newbie Apache's module.
> I'm implementing a new algorithm load balance and extern process repass
> the IP to module.
> Then module redirect requisition to IP's machine.
>
> I try it:
>
> static proxy_worker *find_best_bytest(proxy_balancer *balancer,
> request_rec *r)
>
> int i;
> int valor;
> char* shm_address;
> int shmid;
> key_t shmkey = 5678;
> proxy_worker *mycandidate;
> proxy_worker *worker;
>
> shmid = shmget(shmkey, 50, IPC_CREAT | 0666);
> shm_address = shmat(shmid, NULL, 0);
>
> worker = (proxy_worker*) balancer->workers->elts;
>
> for(i=0; i < balancer->workers->nelts; ++i, ++worker)
> if((valor = strcmp(worker->hostname,shm_address)) == 0)
> mycandidate = worker;
>
> //ap_rprintf(r, "Memoria= %s", shm_address);
>
> But don't correct
>
> Thank you
>
> Ricardo
>
> I hope this helps. If not, I must have some code skeleton at work, I
> can find it tomorrow for you.
>
> S
>
>
--
View this message in context: http://www.nabble.com/APR%2C-Shared-Memory-and-extern-process-tp20566322p20568441.html
Sent from the Apache HTTP Server - Module Writers mailing list archive at Nabble.com.
Re: APR, Shared Memory and extern process
Posted by Sorin Manolache <so...@gmail.com>.
On Tue, Nov 18, 2008 at 20:17, ricardo13 <ri...@gmail.com> wrote:
>
> Hi,
>
> I'm writing a apache's module that comunicate with a extern process.
>
> My extern process is built in C:
>
> char* shm_address;
> int shmid;
> key_t shmkey;
>
> shmkey = 5678;
> shmid = shmget(shmkey, SIZEOFSHMSEG, 0666);
> if (shmid == -1)
> printf("main: shmget() failed\n");
>
> shm_address = shmat(shmid, NULL, 0);
> if ( shm_address==NULL )
> printf("main: shmat() failed\n");
>
> while(1) {
> if(strcmp(shm_address, ":") == 0) {
> strcpy(shm_address, data);
> break;
> }
> }
>
> int rc = shmdt(shm_address);
> if (rc==-1)
> printf("main: shmdt() failed\n");
>
>
> Now I want to write a module that take (or get) the information in this
> segment.
> Can someone help me ??
>
> Thank You
>
> Ricardo
Use the post_config hook because it is run in the parent of all apache
children. There, you simply shmget and shmat. Also, use
apr_pool_register_cleanup in order to register a callback that will
shmdt your shared memory segment when the config pool is destroyed,
i.e. when apache is killed or the configuration reloaded.
I hope this helps. If not, I must have some code skeleton at work, I
can find it tomorrow for you.
S