[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] Trouble getting a response sent from a separate worker t

From: Tom Cornell
Subject: [libmicrohttpd] Trouble getting a response sent from a separate worker thread (with external select)
Date: Tue, 4 Nov 2014 16:16:46 +0000

Hi folks,

I am having some trouble with external select mode getting my call to select() 
to recognize that a response has been queued. The key thing I am trying to 
learn is how to create and queue a response in a different thread from the main 
response handling thread.

Short version: the access handler callback does not create or queue a response, 
but suspends the connection, and queues a task object (including a pointer to 
the suspended MHD_Connection) on a shared queue. A worker thread pops the task 
off the queue, pretends to do some work (the code is just a learning exercise 
at this point), then creates a MHD_Response (using 
MHD_create_response_from_buffer), resumes the connection, and queues the 

Meanwhile, the main loop is waiting for select() to see that something 
happened, but it doesn't notice any changes. The call to select will eventually 
time out (after 15 seconds), and the next time through the main loop it will 
pick up the changes, and the call to MHD_run will cause the response to be 
sent, finally. Clearly I am missing something, since I seem to have managed to 
turn a supposedly event-driven select loop into a polling loop, in effect.

Should this have worked? (I.e., there is evidently a bug or some deeper design 
detail that needs code samples to work out.) Or did I miss an obvious 
high-level step (or two or three)?

I don't mind admitting that I am out of my depth here! (Hey, that's how you 
learn things.) I've used MHD in more conventional settings a few times now, and 
like the library very much, but up until now I've never really plumbed the 
depths this much. I've worked through fileserver_example_external_select.c, and 
I've read a few threads from the archives on asynchronous applications of the 
library, but I'm afraid I have not quite managed to connect all the dots. Any 
advice, further questions, or other help would be most welcome.

Tom Cornell

reply via email to

[Prev in Thread] Current Thread [Next in Thread]