Hi, Thank You, it helps a lot. You have described exactly what I am planning to do.
Best Martin On Thu, Jan 30, 2014 at 2:42 PM, Christian Grothoff <[email protected]> wrote: > 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
