On 02/07/2015 07:00 PM, chaman bagga wrote: > > Hi, Can someone point out whether the variables are valid in the > MHD_AccessHandlerCallback even after returning from callback when > using Suspend / Resume?
Arguments provided by MHD are generally only assured to be valid for the duration of the callback, at least we deliberately did not document anything stronger. If for performance reasons you really cannot afford to copy, the following is true today: With the exception of the "upload_data", the values reachable from the MHD_AccessHandlerCallback won't change (so particular, url, method, version and the "connection values" (URL arguments)). However, you do need to worry about them being destroyed when the connection is finished. While you can listen for that even using a "MHD_RequestCompletedCallback", a multi-threaded implementation will at that point have plenty of fun (deadlocks, races) informing other threads that might use those values of their demise. That is likely to be a bigger performance and correctness nightmare than just copying. Summary: you MUST always copy upload_data, everything else SHOULD be safe until MHD_RequestCompletedCallback(), but relying on it is not encouraged, *especially* if you involve other threads. > I'm running an http server with internal > Select + epoll on linux, with a thread pool consisting of 4 threads. > From MHD_AccessHandlerCallback, I call suspend as my processing > happens asynchronously in a different task. It requires an LDAP > lookup. On getting a response on LDAP, I resume the connection and > enqueue the response from the callback. This is as described in > [libmicrohttpd] Trouble getting a response sent from a separate > worker thread (with external select) > > At present, I am copying all the strings (url, upload_data etc.) as > its not clear if it is safe to pass the pointers to other threads, or > if the pointers are invalid once the callback returns. Response is > appreciated. Chaman > I hope this clarifies the situation! Happy hacking! Christian
signature.asc
Description: OpenPGP digital signature
