Hello
I'm starting with ICS. I need to build a http webservice with 6 worker threads that process jobs. When a new client connection is open, data is fetched into a buffer until completion, by the main thread. Once the data is complete, a job is created, and pushed into one of the job queues (one queue per worker thread, queues are blocking: TThreadedQueue<TJob>) Jobs are processed sequentially through a blocking queue (TThreadedQueue<job>).

I started my code based on the ThrdSvr sample project, but my design is different (I dont spawn one thread per connection) and after many tries, I'm stuck with how to correctly switch the client connection and related message queue from the main thread to the worker thread.

My current pseudo code is:
In HttpServerPosterData: when all the data is received:
    ClientCnx.MyThreadQueue := MyScheduler.LeastLoadedQueue
    ClientCnx.ThreadDetach; // detach from the main thread
    ClientCnx.MultiThreaded := True;
    ClientCnx.ThreadAttached := False;
<build the job and pushes it into the queue assigned to my client>
    // Now I need to wait until the ClientCnx is attached to the thread
    while not(ClientCnx.ThreadAttached) do
        sleep(0);

In MyWorkerThread.Execute
    while not (Terminated)
job := PopItemFromQueue; // blocking until an item at least is available
        job.ClientCnx.ThreadAttach;
        job.ClientCnx.ThreadAttached := True;

But the code does not work, as the queue may be loaded, forcing the main thread to wait for the job to be popped before continuing... Is there a way to attach the ClientCnx to the target thread, from the main thread? (in place of the while / sleep(0) loop) It seems that the window handle of the client socket can be created with a ThreadID as argument?

I'm beginning with ICS so I may not use the right approach.
The TWSocketThrdServer component seems perfect for what I need (just need to override the AcquireThread method), but it's a tcp server and I need http support...

Thanks for your advises,
Laurent
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to