[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] Trouble getting a response sent from a separate work
From: |
Tom Cornell |
Subject: |
Re: [libmicrohttpd] Trouble getting a response sent from a separate worker thread (with external select) |
Date: |
Tue, 4 Nov 2014 19:11:13 +0000 |
> Date: Tue, 04 Nov 2014 18:44:53 +0100
> From: Christian Grothoff <address@hidden>
> To: address@hidden
> Subject: Re: [libmicrohttpd] Trouble getting a response sent from a
> separate worker thread (with external select)
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset="windows-1252"
>
> 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
First off, thanks for the quick reply!
(1) Yes -- In particular, the call to MHD_queue_response returned MHD_YES.
(And the response did eventually get sent, only select() had to time out
first.
Then control returned to the main loop and the next call to select()
picked up the response and sent it.)
(2) I did set the USE_SUSPEND_RESUME flag on starting the daemon.
(Learned that lesson early on.)
(3) I guess this must be the problem then.
So I can create the MHD_Response and queue it in the access handler,
but fill in the response data (status code, body) elsewhere, at a later time?
Do I need to be using MHD_create_response_from_callback to create
the MHD_Response? Or does that not matter?
This is version 0.9.37, built from source on CentOS 6, just for completeness.
Thanks!
Tom
>
> 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
> >
> >
> >
>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: signature.asc
> Type: application/pgp-signature
> Size: 181 bytes
> Desc: OpenPGP digital signature
> URL:
> <http://lists.gnu.org/archive/html/libmicrohttpd/attachments/20141104/f42
> 7c06d/attachment.pgp>
>
> ------------------------------
>
> _______________________________________________
> libmicrohttpd mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/libmicrohttpd
>
>
> End of libmicrohttpd Digest, Vol 67, Issue 7
> ********************************************