libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] Block size in MHD_create_response_from_callback


From: Christian Grothoff
Subject: Re: [libmicrohttpd] Block size in MHD_create_response_from_callback
Date: Wed, 29 Jul 2009 17:22:12 +0200
User-agent: KMail/1.11.4 (Linux/2.6.30-1-686; KDE/4.2.4; i686; ; )

On Wednesday 29 July 2009 14:06:05 Andre Colomb wrote:
> Howdy all!
>
> Just ran into some trouble when trying to build responses from a
> callback function. It seems that the "max" parameter to the callback is
> always 2048 bytes until the last block is reached, no matter what I
> specify as block_size.
>
> However, when setting it to a value lower than 2048 (tried with 1024), I
> get segfaults, presumably because the buffer allocated is too small.
> Larger values don't cause the segfaults but the "max" parameter is still
> only 2048. Here is the output from my application's
> MHD_ContentReaderCallback function. The first number is its return
> value, second is the "max" argument and third is the "pos" argument.

I found a bug in the code that would use the user-specified buffer size for 
allocation but then store another value (older default of 2048) for what 
should be used, which explains why you saw no change in buffer size and the 
segfault.  This is now fixed in SVN HEAD.  Thanks for reporting.

> [2009-07-29 13:25:54.759] DEBUG_COMM: <VxmlServer> Read 2048 of 2048
> bytes from file at position 0
> [2009-07-29 13:25:54.759] DEBUG_COMM: <VxmlServer> Read 2048 of 2048
> bytes from file at position 0
> [2009-07-29 13:25:54.759] DEBUG_COMM: <VxmlServer> Read 2048 of 2048
> bytes from file at position 2048
> [2009-07-29 13:25:54.759] DEBUG_COMM: <VxmlServer> Read 2048 of 2048
> bytes from file at position 4096
> [2009-07-29 13:25:54.759] DEBUG_COMM: <VxmlServer> Read 2048 of 2048
> bytes from file at position 6144
> [2009-07-29 13:25:54.759] DEBUG_COMM: <VxmlServer> Read 1941 of 1941
> bytes from file at position 8192
>
> Please also note that this does not match the documented behavior,
> quote: "MHD guarantees that pos will be the sum of all non-negative
> return values obtained from the content reader so far."

Hmm.  That guarantee only holds if the same response object is not re-used 
between different sessions, but that's another story (I should probably improve 
the docs).  Still, unless the first call belongs to a different connection 
entirely, the above log looks fishy.  However, I can not find anything in the 
code that would explain  it -- the offset argument is incremented by exactly 
the number of bytes returned by your callback.  I would appreciate it if you 
could provide a (simple) testcase that would allow me to reproduce this 
behavior.

> This is not true for the second call where pos should be 2048 instead of
> 0. I am not re-using the response object and the total response length I
> specified was 10133.
>
> My libmicrohttpd version is 0.4.1 with PlibC 0.1.3, unfortunately I
> couldn't manage to use 0.4.2 so far.

The bug you mentioned clearly is still present in 0.4.2.  It will be fixed in 
0.4.3 and higher (at least the buffer-size/segfault portion).

Best,

Christian





reply via email to

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