libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] may libmicrohttpd change the connection pointer


From: Christian Grothoff
Subject: Re: [libmicrohttpd] may libmicrohttpd change the connection pointer
Date: Thu, 30 Jan 2014 14:42:13 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10

On 01/30/2014 01:15 PM, Martin Velek wrote:
> Hello,
> 
> do not you know, can I rely on "constant" struct MHD_Connection
> *connection pointer passed to (*MHD_AccessHandlerCallback)? The
> constant is meant as not varying during a single connection. It is
> quite difficult to explain for me so let me outline the example :)
> 
> The problem:
> I need to access URI parameters in the response callback.
> 
> The solution:
> The function (*MHD_AccessHandlerCallback) creates a response from
> callback by passing (*MHD_ContentReaderCallback) to the function
> MHD_create_response_from_callback. The pointer to struct
> MHD_Connection * is stored in the crc_cls (extra argument to crc).
> 
> In the (*MHD_ContentReaderCallback) callback, the void *cls is casted
> to struct MHD_Connection * and call MHD_get_connection_values to get
> values.
> 
> The problem appears when the libmicrohttpd somehow reallocates the
> connection pointer internally during the next call of
> (*MHD_AccessHandlerCallback) or (*MHD_ContentReaderCallback). I
> remind, I think only one connection => *con_cls != NULL previusly set
> to something different from NULL.
> 
> The story above can be also summarized to this question:
> How can I access the connection information from the response callback?

You can safely pass the connection as the closure to your response
callback (or pass some other struct that you defined that has a pointer
to the connection in it), but in those cases you must not share the
'response' object with multiple connections (which you are otherwise
free to do).

I hope this helps!

Happy hacking!

-Christian

Attachment: 0x48426C7E.asc
Description: application/pgp-keys

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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