libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] Trouble getting a response sent from a separate work


From: Christian Grothoff
Subject: Re: [libmicrohttpd] Trouble getting a response sent from a separate worker thread (with external select)
Date: Tue, 04 Nov 2014 18:44:53 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.1.2

Dear Tom,

Did you pass the "MHD_USE_SUSPEND_RESUME" flag? Also, you're not
supposed to call 'MHD_queue_response" from anywhere but the access
handler callback, so if you call it from another thread, the behavior is
not defined (or, more likely, you got an error value returned and thus
your response was NOT actually queued but refused --- did you check the
return value?).

So please (1) check return values, (2) pass USE_SUSPEND_RESUME, and
(3) call 'resume' from the other thread but queue the reply in the
access handler.  After that, it should work. If it does not, make sure
you run a recent MHD release. If that still fails, a testcase to
reproduce would likely be helpful...

Happy hacking!

Christian

On 11/04/2014 05:16 PM, Tom Cornell wrote:
> 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 
> response. 
> 
> 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
> 
> 
> 

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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