libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] MHD_create_response_from_callback


From: Regis Louge
Subject: Re: [libmicrohttpd] MHD_create_response_from_callback
Date: Mon, 12 Sep 2011 12:13:23 +0200

Hi Christian,

Thank you for your answer, it helps understanding the problem. I am currently using the one-thread-per-connection MHD, but still I would like to handle client disconnects as fast as possible. To do so, I was thinking about, when sending the push notification test all the "push" connections in order to check if the client is still connected and if not then shut it down. My only concern is the retrieving of informations from the connections, indeed MHD_get_connection_info doesn't have that feature. Nevertheless i found http://lists.gnu.org/archive/html/libmicrohttpd/2010-02/msg00007.html while searching, is the 'still connected' implemented ? Do you agree on the fact that it is the only solution ?


On Fri, Sep 9, 2011 at 1:49 PM, Christian Grothoff <address@hidden> wrote:
Hi Regis,

I've written a new testcase based on your specifications, and I'm now even more
convinced that there is no bug.  The testcase will shortly be in SVN HEAD.
The test starts a MHD server (using most available threading modes) and forks
a 'curl' process for the download. MHD then generates an "infiinte" webpage of
"d" characters and the test driver eventually (after ~1s) kills curl
(SIGTERM).  The test driver then checks that the cleanup function is indeed
called.

Now, there is one *unusual* case which might have tripped you up (certainly
tripped me up when writing the testcase at first) in case of the multithreaded
(one-thread-per-connection) MHD.  Here, the "cleanup" function is only called
after MHD accepts the *next* inbound connection -- or upon MHD shutdown.

The reason for this is simple: the master MHD thread sleeps until it is awoken
from listen and only then cleans up 'left-over' connections. This, potentially
'untimely' cleanup is usually not an issue as it still avoids unbounded (or
even large) resource consumption.  However, if you test with only a single
connection and without MHD_daemon_stop, you would think that MHD failed to
call your cleanup function.  Just remember this: the API guarantees that your
cleanup function will be called, but it makes no claims as to when exactly
this will happen exactly.


I hope this helps!

Happy hacking!

Christian

On Thursday, September 08, 2011 08:41:46 PM Regis Louge wrote:
> Here is my callback function :
>
> static ssize_t
> push_callback (void *cls, uint64_t pos, char *buf, size_t max)
> {
>     PushElement *push = cls;
>     if(push->pushReceived == 1){
>         ...
>         Store push data in buf
>         ...
>         return strlen(buf);
>     }
>     else return 0;
> }
>
> In my answer_to_connection for the URL /push I have :
>
> response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
>                                                          32 * 1024,
>                                                          &push_callback,
>                                                          push,
>
> &push_free_callback);
>            if(response == NULL)
>            {
>           return MHD_NO;
>            }
>            MHD_add_response_header (response, "Content-Type", "text/html;
> charset=utf-8");
>            ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
>            MHD_destroy_response (response);
>            return ret;
>
> For a test case, when my client accesses to /push using curl -N -GET
> ".../push" he receives all the push notifications like it is suppose to,
> when I cancel it (^C), nothing happens on my server, request_completed is
> not called and neither is push_free_callback (which is the cleanup
> function)
>
> On Thu, Sep 8, 2011 at 8:19 PM, Christian Grothoff
>
> <address@hidden>wrote:
> > Hi!
> >
> > Can you provide some kind of testcase that shows that MHD doesn't
> > properly call the cleanup function?
> >
> > Happy hacking!
> >
> > Christian
> >
> > On Thursday, September 08, 2011 12:56:13 PM Regis Louge wrote:
> > > Hi,
> > >
> > > I am currently trying to implement push notifications using
> > > libmicrohttpd and MHD_create_response_from_callback returning 0 until
> > > an event triggers the push. This seems to work pretty fine except for
> > > when the client interrupts the communication, then the cleanup method
> > > is not called and thus creates a lot of problems and impossibility to
> > > "subscribe" again to the push stream.
> > >
> > > --
> > > Regis



--
Régis LOUGE
Eleve Ingénieur 5° année - ECE Paris - Aalborg Universitet
Mail : address@hidden
Tel : +33 6 62 51 40 91

reply via email to

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