libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] infinite loop even when connection is closed by clie


From: Leandro Santiago
Subject: Re: [libmicrohttpd] infinite loop even when connection is closed by client in the create_response_from_callback when max < buffer size
Date: Fri, 21 Jan 2011 10:03:32 -0200

Sorry wait to reply!

2011/1/19 Christian Grothoff <address@hidden>
Hi!

First of all, which threading mode are you using? (external select, internal
select, thread-per-connection?).  Also, are you using chunked encoding or not?
 
I'm using MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG option flags and no (0) timeout to start the daemon. About chunked encoding, are you talking about the header "Transfer-Encoding: chunked"? I'm sending the data as a normal file, a sequence of bytes. The only difference is these bytes don't exist in disk, they are generated in runtime. I'm not using this header. But even when I add it, the behavior is the same. What I do is generate something with size less than 360000 bytes, copy them into the buf via memcpy and return the size of this data.

What's the meaning of the max parameter?
 

In any case, looking at the code (there are two places in connection.c where
we call the content reader callback, both with the format "response->crc", the
'max' argument should always be either block_size (unchunked) or block_size -
12 (chunked encoding), unless you're at the end of the file (which for
MHD_SIZE_UNKNOWN you'd never be).
 
When everything runs fine (for example, using mplayer as client) every block has the correct size and max also has this same value.


So a value of 16372 is rather strange (359988 OTOH should be something you
ought to have to deal with...).  Could you answer the above questions and
maybe also supply a stack trace with the values of the "response" and
"connection" structs on the stack upon the time of the call?

Finally, in terms of being called "forever", you may want to add a timeout to
your connections (option to MHD_start_daemon).

Now I discovery what is the number 16372:
It's (2^14)-12 = 16384 - 12 = 16372

So I think I'm sending chunked data and the maximum size of data that the web browsers support is 2^14 bytes.

So I have one question: when I pass to the create_response_from_callback the buffer size, does it mean I need to return a data with this exactly size?

So I reduced the size passed to this function (and changed some internal logic about the size of buffer), now everything is working fine :-)

Thanks a lot.


Happy hacking,

Christian

On Wednesday 19 January 2011 13:37:37 Leandro Santiago wrote:
> Hello to all. I'm streaming videos via http using libmicrohttpd.
>
> To do it, I'm using the MHD_create_response_from_callback, using a callback
> with the interface:
>
> static ssize_t video_generator(void* cls, uint64_t pos, char* buf, size_t
> max);
>
> When I call MHD_create_function_from_callback, I'm passing the value 360000
> as the block_size and MHD_SIZE_UNKNOWN as size;
>
> The problem is sometimes the max value isn't 360000, but a lower value
> (16372).
>
> As I can't work with this low value, I ask, in the beginning of
> video_generator:
>
> if (max < 360000) return 0;
>
> The problem is thereafter this function (video_generator) is called
> everytime, indefinitely, passing max as 16372 and the "pos" value as 0.
> Even if I close the connection (closing the client, for example), the
> video_generator callback continues indefinitely, with the same values (max
> = 16372 and pos = 0). So I need to kill the process.
>
> For example, the above behavior happens when I use any webbrowser as
> client, but doesn't happen when I use mplayer (which supports http
> protocol).
>
> What this function does is: everytime it's called, it sends one frame to
> the client.


reply via email to

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