[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] Understanding minimal_example.c
From: |
arnuld uttre |
Subject: |
[libmicrohttpd] Understanding minimal_example.c |
Date: |
Mon, 20 Apr 2009 15:28:58 +0530 |
This is some part of the code from minimal_example.c that is
distributed with the libmicrohttpd source. I have some questions over
it which manual does not explain:
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 aptr;
const char *me = cls;
struct MHD_Response *response;
int ret;
printf("--------------------------------------------------------------------------------\n");
printf("upload_datae = %s\n", upload_data);
if (0 != strcmp (method, "GET"))
return MHD_NO; /* unexpected method */
if (&aptr != *ptr)
{
/* do never respond on first call */
*ptr = &aptr;
return MHD_YES;
}
*ptr = NULL; /* reset when done */
response = MHD_create_response_from_data (strlen (me),
(void *) me, MHD_NO, MHD_NO);
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
MHD_destroy_response (response);
return ret;
}
-------------------------------------------------------------
> if (0 != strcmp (method, "GET"))
> return MHD_NO; /* unexpected method */
why we are returning with MHD_NO when the method is GET and not for
other methods ?
> /* do never respond on first call */
> *ptr = &aptr;
> return MHD_YES;
> }
> *ptr = NULL; /* reset when done */
Why never respond to the first attempt of the client ? I am, in my
software, not using any check for GET method. I also respond to the
very first call and just set the pointer to some value and then I
never set it to NULL again. What harm I am doing to my program ?
Last, *ptr = &aptr and aptr is not initialized with some value. Can't
it produce Segfault ?
--
http://uttre.wordpress.com/2008/05/14/the-lost-love-of-mine/
- [libmicrohttpd] Understanding minimal_example.c,
arnuld uttre <=