libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] NOTIFY_COMPLETED


From: Christian Grothoff
Subject: Re: [libmicrohttpd] NOTIFY_COMPLETED
Date: Sat, 3 Aug 2024 23:20:58 +0200
User-agent: Mozilla Thunderbird

Hi MrDave,

You're not exactly doing anything wrong, there is simply no guarantee (by the MHD API) as to when the ContentReaderFreeCallback will be called other than "after MHD is done with the response". So MHD _could_ call it before or after the NOTIFY_COMPLETED callback, so your code should not rely on any particular ordering here.

Happy hacking!

Christian

On 8/3/24 10:05 PM, MrDave wrote:
Hi,

I am using libmicrohttpd in my application and am seeing an unexpected sequence of function calls and am wondering if this is expected or whether there is something that I've set up incorrectly.

When initiating the daemon, I am setting callbacks for both MHD_OPTION_URI_LOG_CALLBACK and MHD_OPTION_NOTIFY_COMPLETED.  Then upon answering the request I am doing a MHD_create_response_from_callback.

What I'm observing is that the MHD_OPTION_NOTIFY_COMPLETED function is called before the ContentReaderFreeCallback function from the response callback.  My expectation was that the callback "cleanup" would have been called before the "notify completed".

The following code snippets may better explain the question.  I am seeing that the 'mhd_deinit' function is being called before the 'file_free' function.

----snip-----
   mhd_ops[0].option = MHD_OPTION_URI_LOG_CALLBACK;
   mhd_ops[0].value = (intptr_t)mhd_init;
   mhd_ops[0].ptr_value = NULL;

   mhd_ops[1].option = MHD_OPTION_NOTIFY_COMPLETED;
   mhd_ops[1].value = (intptr_t)mhd_deinit;
   mhd_ops[1].ptr_value = NULL;

   mhd_ops[2].option = MHD_OPTION_END;
   mhd_ops[2].value = 0;
   mhd_ops[2].ptr_value = NULL;

  daemon = MHD_start_daemon (MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD,
                              PORT, NULL, NULL,
                              &answer_to_connection, NULL
                              , MHD_OPTION_ARRAY, mhd_ops
                              , MHD_OPTION_END);

----snip-----

response = MHD_create_response_from_callback (
             webua->sz, 32 * 1024, &file_reader, webua, &file_free);
   ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
   MHD_destroy_response (response);

Thanks.
MrDave



reply via email to

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