Hi Vlad,
>> Is that possible to implement something like a stateful web-server
>> with ACE?
Sure.
>> Its work could be described the following way:
>>
>> - As long as a thread-pool there is a pool of allocated handler objects,
>> which could be spare or used.
>> - Spare handler objects lie somewhere in memory, used ones do their work
>> in threads - one thread per one object.
Right.
>> - Acceptor waits for a connection on the specified TCP port or unix socket.
>> - When a connection arrives, Acceptor uses programmer-redefined routine
>> to check its conformity to one of the spare Handler objects.
Right, you could do this as follows:
1. Derive a class from ACE_Acceptor called something like Cached_Acceptor
2. Make the Cached_Acceptor::make_svc_handler() hook method a no-op
3. Make the Cached_Acceptor::accept_svc_handler() hook method do the
following:
>> If the conformity could not be found, the request is considered
>> "general". The conformity is usually checked by looking into the
>> data received from client.
>> - Once the conformity is found, the appropriate Handler object becomes
>> "used", and its handle_input() is called in a separate thread. If
>> there're no spare threads at the moment, an error message is returned to
>> the client.
>> - Object's handle_input() deals with the request. After that the object
>> isn't destroyed, but becomes spare again. Its thread therefore also
>> becomes spare.
>>
>> - Spare object are destroyed after a request timeout.
You can use ACE_Reactor::schedule_timer() and
ACE_Reactor::cancel_timer() to do this.
>> - There're also "general" handler objects, which are never destroyed, and
>> they handle "general" requests.
>>
>> I couldn't find the description of such a behaivor in ACE docs. But
>> implementing all this from scratch looks like reinventing the wheel.
It should be pretty trivial to do this with ACE_Acceptor.
Take care,
Doug
--
Dr. Douglas C. Schmidt, Associate Professor TEL: (949) 824-1901
Dept of Electrical & Computer Engineering FAX: (949) 824-2321
616E Engineering Tower WEB: www.ece.uci.edu/~schmidt/
University of California, Irvine, 92697-2625 NET: schmidt@...