Re: [libmicrohttpd] MHD_CONNECTION_OPTION_TIMEOUT seems not to work with MHD_create_response_from_callback

2019-02-02 Thread Christian Grothoff
Hi Nicolas,

You are right to use the timeout option here. Beyond that, there is
nothing you can do. If the connection of the client is merely bad (but
not closed), TCP will keep retrying and eventually succeed, possibly
preventing the timeout from being effective. That not enough data
arrives in a timely fashion for the Web radio to work is outside of the
scope of HTTP -- IMO your best shot is to increase the buffer size on
the client side in that case.

On the server side, make sure you use EPOLL, in that case even a few
hundred thousand 'open' connections should not be a huge issue for the
server.

My 2 cents

Christian

On 1/31/19 7:58 PM, Nicolas Mora wrote:
> Hello,
> 
> Although it's not easy to reproduce, it seems that using connection
> option MHD_CONNECTION_OPTION_TIMEOUT when streaming data with
> MHD_create_response_from_callback seems not to work, although.
> 
> In my application with MHD underneath where the problem occurs, I
> provide a webradio, which is a http stream with unlimited size.
> 
> The problem I have is when the client uses a bad wifi connection, or
> when the client moves too far from the wifi antenna, then the client
> device detects the connection is wrong, therefore closes it, but on the
> server side, the connection remains open and never closes, leading to
> phantom connections.
> 
> If I use MHD_OPTION_CONNECTION_TIMEOUT in MHD_start_daemon, this
> partially fixes the problem, the server automatically closes the
> connection after the mentionned seconds of total inactivity from the
> client (i.e. the client is not reading the stream anymore but keeps the
> connection open), but it doesn't fix the problem for bad connections.
> 
> I'm attaching a simple example that I used to be able to reproduce the
> problem, but I couldn't find a way to reproduce it with a client
> program. Maybe by using netem but I'm not familiar with this command.
> 
> /Nicolas



Re: [libmicrohttpd] MHD_CONNECTION_OPTION_TIMEOUT seems not to work with MHD_create_response_from_callback

2019-02-02 Thread Nicolas Mora
Hello,

Le 19-02-02 à 05 h 29, Christian Grothoff a écrit :
> 
> You are right to use the timeout option here. Beyond that, there is
So you confirm that MHD_CONNECTION_OPTION_TIMEOUT is not available when
using MHD_create_response_from_callback?

> On the server side, make sure you use EPOLL, in that case even a few
> hundred thousand 'open' connections should not be a huge issue for the
> server.
> 
So I'f I understand the documentation, instead of using
MHD_USE_THREAD_PER_CONNECTION, I should use
MHD_USE_EPOLL_INTERNAL_THREAD, except for windows platforms.

Thanks for your help!

/Nicolas



Re: [libmicrohttpd] websocket example

2019-02-02 Thread silvioprog
Indeed. But the next messages from José and Nicolas encouraged us... :-)

On Tue, Jan 29, 2019 at 6:44 PM Moritz Warning  wrote:

> I saw libmicrohttpd-ws, but it was not working for me.
> (there is an error when I press connect on the demo site)
>
> Also, I do not see if this is a modified version of libmicrohttpd.
> Then there is also lib/libwebsockets/, which seems to be an additional lib.
>
> On 1/29/19 6:38 PM, silvioprog wrote:
> > Hi Moritz,
> >
> > I have interesting on it too (issued at:
> > https://gnunet.org/bugs/view.php?id=5501). Some days ago I found an
> example
> > which can be used as a start point to develop a small example:
> >
> > https://github.com/giovanni-liboni/libmicrohttpd-ws
> >
> > I don't tested it yet, but the implementation seems very simple and
> depends
> > only on MHD. :-)
> >
> > best,
> >
> > On Tue, Jan 29, 2019 at 1:21 PM Moritz Warning 
> wrote:
> >
> >> Hi,
> >>
> >> can someone point me to an example of using websockets with
> libmicrohttpd?
> >>
> >> thanks,
> >> mwarning
> >>
> >
>
>
>

-- 
Silvio Clécio


Re: [libmicrohttpd] websocket example

2019-02-02 Thread silvioprog
Hello José,

I couldn't test it yet, but it is in my whishlist. Thanks again for sharing
it! :-)

On Wed, Jan 30, 2019 at 4:17 PM José Bollo  wrote:

> On Tue, 29 Jan 2019 16:16:59 +0100
> Moritz Warning  wrote:
>
> > Hi,
> >
> > can someone point me to an example of using websockets with
> > libmicrohttpd?
> >
> > thanks,
> > mwarning
> >
>
> I implemented WS over LMHD. Try to pull starting from function
> check_websocket_upgrade in
>
> https://git.automotivelinux.org/src/app-framework-binder/tree/src/afb-websock.c#n167
>
> Not sure it will help but...
>
> Best regards
> José
>
>

-- 
Silvio Clécio


Re: [libmicrohttpd] websocket example

2019-02-02 Thread silvioprog
Hello Nicolas,

I took a look at your code and it is very interesting. Maybe it could help
us to create a minimal WS example to be distributed in the MHD examples.
Also, I'll reuse it as base to create a very tiny layer to distribute in a
library I'm maintaining. All your/José's codes will help me a lot, and I
think it will help Moritz too. :-)

On Wed, Jan 30, 2019 at 4:49 PM Nicolas Mora  wrote:

> Hello,
>
> Le 2019-01-29 10:16, Moritz Warning a écrit :
> >
> > can someone point me to an example of using websockets with
> > libmicrohttpd?
> >
> As others, I made an implementation of a websocket service with MHD
> underneath.
> https://github.com/babelouest/ulfius/blob/master/src/ulfius.c#L529
>
> Mine is so entangled with the framework above MHD that it's probably not
> the better example to understand websockets service with MHD though.
>
> /Nicolas
>
>

-- 
Silvio Clécio


Re: [libmicrohttpd] tiny websocket above LMHD

2019-02-02 Thread silvioprog
Hello José,

first, thanks for this awesome work! I took a look at the sources and it
seems very clean. I'll test it on Windows. I saw you did the client too, so
it will be very helpful for who those want to study WS.

But, I have two questions: is it very difficult to do a minimal WS example
to distribute in the MHD examples? If so, will mark the #5501
 as 'won't fix' and close the
issue. The other question is if it could be used as dependency in a library
under LGPL license.

Once more, thank you very much for sharing it! ☺

On Fri, Feb 1, 2019 at 3:57 PM José Bollo  wrote:

> I am proud to share with you a tiny implementation of websocket with
> libmicrohttpd.
>
> You can find it there:
>
>https://gitlab.com/jobol/lmhd-ws
>
> I tried to give something small and useful (based on some previous work
> I made).
>
> It is not perfect so feedback are welcome. Especially I only work on
> linux. People on Mac or BSD are welcome to submit issues or pull
> requests. People of windows also of course.
>
> Best regards
> José Bollo


-- 
Silvio Clécio