logo       

Waiting on more then one event -- Accept_r: msg#00001

web.fastcgi.devel

Subject: Waiting on more then one event -- Accept_r

Hello,

There is a problem when I want to work with
multiple threads and receive other notifications
for example, timeout, cache notifications etc.

The purposed solution on the lists is:

pthread_mutex_lock
select(incoming fd,other event fd,timeout)
FCGX_Accept_r()
pthread_mutex_unlock

Comments:
- I can't do select outside lock because
I may find two threads accepting same request
and one of them being blocked.
- FCGX_Accept_r does much more then just accept
reads environment parameters from the socket
etc... All this time other threads can not
accept new connections.

For me ideal solution would be calling accept
outside the socket, unlocking mutex and continuing
to normal Accept_r.

Something like that.
pthread_mutex_lock
select(incoming fd,other event fd,timeout)
new_sock=accept(fd);
pthread_mutex_unlock
FCGX_Accept_r(new_sock)

Viewing the fcgiapp.c code I found that Accept_r
checks whether icpFd assigned the value, thus
I tried following way:
request->ipcFd=
accept(main_fd, (struct sockaddr *)&sa,&len);
request->keepConnection=1;
and then
FCGX_Accept_r(request)

It seems to be work and I had written a simple
program based on thread.c based on this techique
that accepts external signal (SIGINT) and performs
nice shutdown.

But I'm absolutely not sure if:
- is this correct way to do things?
- may this change in future?
- can similar API be added to the library?
if such way is OK I may write a patch and send.


Thanks,
Artyom

P.S.: The program is attached.

Attachment: threaded.c
Description: 3561867335-threaded.c

___________________________________
fastcgi-developers mailing list
http://fastcgi.com/fastcgi-developers/
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise