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

8.1 Enqueuing a response

Function: int MHD_queue_response (struct MHD_Connection *connection, unsigned int status_code, struct MHD_Response *response)

Queue a response to be transmitted to the client as soon as possible (increment the reference counter).

connection

the connection identifying the client;

status_code

HTTP status code (i.e. 200 for OK);

response

response to transmit.

Return MHD_YES on success or if message has been queued. Return MHD_NO: if arguments are invalid (example: NULL pointer); on error (i.e. reply already sent).

Function: void MHD_destroy_response (struct MHD_Response *response)

Destroy a response object and associated resources (decrement the reference counter). Note that MHD may keep some of the resources around if the response is still in the queue for some clients, so the memory may not necessarily be freed immediatley.

An explanation of reference counting(1):

  1. a MHD_Response object is allocated:
     
    struct MHD_Response * response = MHD_create_response_from_data(...);
    /* here: reference counter = 1 */
    
  2. the MHD_Response object is enqueued in a MHD_Connection:
     
    MHD_queue_response(connection, , response);
    /* here: reference counter = 2 */
    
  3. the creator of the response object discharges responsibility for it:
     
    MHD_destroy_response(response);
    /* here: reference counter = 1 */
    
  4. the daemon handles the connection sending the response's data to the client then decrements the reference counter by calling MHD_destroy_response(): the counter's value drops to zero and the MHD_Response object is released.

This document was generated by Christian Grothoff on November, 16 2008 using texi2html 1.78.