libmicrohttpd
[Top][All Lists]
Advanced

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

[libmicrohttpd] must_free & must_copy for MHD_create_response_from_data


From: Basile Starynkevitch
Subject: [libmicrohttpd] must_free & must_copy for MHD_create_response_from_data
Date: Wed, 29 Dec 2010 12:50:15 +0100

Hello All,

First, a small wish: for readability purposes, add at least
enum { MHD_DONT_FREE=0,
       MHD_MUST_FREE};
enum { MHD_DONT_COPY=0,
       MHD_MUST_COPY};
to microhttpd.h (or the equivalent #define-s).

I find much more readable a call like:
  resp = MHD_create_response_from_data (mysize,
                                        mydata,
                                        MHD_MUST_FREE, MHD_MUST_COPY);
than just
  resp = MHD_create_response_from_data (mysize,
                                        mydata,
                                        MHD_YES, MHD_YES);

Second, a question:
Does haveing the must_free argument to false and must_copy argument to true 
makes sense?
I suggest at least adding a comment explaining what happens in that case.

Perhaps a bettter signature would be

/* mode for handling data for responses */
enum mhd_response_memory_mode_en {
  /* the data won't be freed or copy by libmicrohttpd, e.g. because it is a 
static buffer */
  MHD_RESPMEM_NONE,

  /* the data will be freed by libmicrohttpd when done. */ 
  MHD_RESPMEM_MUST_FREE,

  /* the data is copied to a private buffer and will be then freed by 
libmicrohttpd when done. */
  MHD_RESPMEM_MUST_COPY
};

And add a call

/**
 * Create a response object.  The response object can be extended with
 * header information and then be used any number of times.
 *
 * @param size size of the data portion of the response
 * @param data the data itself
 * @param mode the mode to handle the data
 * @return NULL on error (i.e. invalid arguments, out of memory)
 */
struct MHD_Response* MHD_create_response_from_data_modal (size_t size,
                                                          void* data,
                                                          enum 
mhd_response_memory_mode_en mode);

Regards and happy new year.

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***



reply via email to

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