[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8.2 Creating response objects

Function: struct MHD_Response * MHD_create_response_from_callback (size_t size, unsigned int block_size, MHD_ContentReaderCallback crc, void *crc_cls, MHD_ContentReaderFreeCallback crfc)

Create a response object. The response object can be extended with header information and then it can be used any number of times.

size

size of the data portion of the response, -1 for unknown;

block_size

preferred block size for querying crc (advisory only, MHD may still call crc using smaller chunks); this is essentially the buffer size used for IO, clients should pick a value that is appropriate for IO and memory performance requirements;

crc

callback to use to obtain response data;

crc_cls

extra argument to crc;

crfc

callback to call to free crc_cls resources.

Return NULL on error (i.e. invalid arguments, out of memory).

Function: struct MHD_Response * MHD_create_response_from_data (size_t size, void *data, int must_free, int must_copy)

Create a response object. The response object can be extended with header information and then it can be used any number of times.

size

size of the data portion of the response;

data

the data itself;

must_free

if true: MHD should free data when done;

must_copy

if true: MHD allocates a block of memory and use it to make a copy of data embedded in the returned MHD_Response structure; handling of the embedded memory is responsibility of MHD; data can be released anytime after this call returns.

Return NULL on error (i.e. invalid arguments, out of memory).

Example: create a response from a statically allocated string:

 
const char * data = "<html><body><p>Error!</p></body></html>";

struct MHD_Connection * connection = ...;
struct MHD_Response *   response;

response = MHD_create_response_from_data(strlen(data), data,
                                         MHD_NO, MHD_NO);
MHD_queue_response(connection, 404, response);
MHD_destroy_response(response);

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Christian Grothoff on May, 26 2008 using texi2html 1.78.