libmicrohttpd
[Top][All Lists]
Advanced

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

[libmicrohttpd] Asynchronous communication


From: zack Hasit
Subject: [libmicrohttpd] Asynchronous communication
Date: Thu, 21 Feb 2013 21:33:21 -0500

Hi,

I am trying to implement a non synchronous implementation. Please let me know if this is possible as per explanation below.

In example below the response is created right away in same thread and function. What I want to do is once I get the request in this function I want to put it in a separate queue for extra processing and then return with no response right away. I want to return from this function such that the thread is released to process new requests while another process processes on this request in the queue.

The queue mentioned above will be read by some other process and it will create a response for it and send it back asynchronously back to this processes implementing the web service. When I receive that response I will create web service response (maybe with MHD_create_response_from_data??) . Is there a way to the get it forwarded to right client ?

As you can see that this is asynchronous unlike regular web services. Is this possible ?

Thanks

static int ahc_echo(void * cls,
		    struct MHD_Connection * connection,
		    const char * url,
		    const char * method,
                    const char * version,
		    const char * upload_data,
		    size_t * upload_data_size,
                    void ** ptr) {
  static int dummy;
  const char * page = cls;
  struct MHD_Response * response;
  int ret;

  if (0 != strcmp(method, "GET"))
    return MHD_NO; /* unexpected method */
  if (&dummy != *ptr) 
    {
      /* The first time only the headers are valid,
         do not respond in the first round... */
      *ptr = &dummy;
      return MHD_YES;
    }
  if (0 != *upload_data_size)
    return MHD_NO; /* upload data in a GET!? */
  *ptr = NULL; /* clear context pointer */
  response = MHD_create_response_from_data(strlen(page),
					   (void*) page,
					   MHD_NO,
					   MHD_NO);
  ret = MHD_queue_response(connection,
			   MHD_HTTP_OK,
			   response);
  MHD_destroy_response(response);
  return ret;
}


reply via email to

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