FCGX_Accept_r bad design?
"stefano marengo" <[email protected]>
| Newsgroups | gmane.comp.web.fastcgi.devel,gmane.spam.detected |
|---|---|
| Message-ID | <[email protected]> |
I am new to fastcgi, I'm trying to run a simple threaded application
like described in:
http://www.fastcgi.com/archives/fastcgi-developers/2005-March/003627.html
I want a single accept loop and then some worker threads (or thread-pool).
FCGX_Request FcgiReq;
FCGX_InitRequest(&FcgiReq, 0, 0);
while (FCGX_Accept_r(&FcgiReq) >= 0)
{
pcreate_thread(&WorkerThread, 0, (void*)&WorkerThreadFunc, 0);
}
...
WorkerThreadFunc(...)
{
// Do the work.
}
But this can't work because FCGX_Accept_r overwrites FCGX_Request being
processed by the worker!
The only working method is (like Threaded.c example does):
pcreate_thread(&AcceptThread, 0, (void*)&AcceptThreadFunc, 0);
...
AcceptThreadFunc(...)
{
FCGX_Request FcgiReq;
FCGX_InitRequest(&FcgiReq, 0, 0);
while (FCGX_Accept_r(&FcgiReq) >= 0)
{
// Do the work.
}
}
But I would like to use the first approach.
I don't understand why the prototype of FCGX_Accept_r is not something like:
DLLAPI FCGX_Request *FCGX_Accept_r(int sock);
In this way the following code would be correct (FCGX_Accept_r allocates
itself a new request each time):
while ((request = FCGX_Accept_r(listen_socket)))
{
pcreate_thread(&WorkerThread, 0, (void*)&WorkerThreadFunc, request);
}
Thanks a lot,
stef
___________________________________
fastcgi-developers mailing list
http://fastcgi.com/fastcgi-developers/