libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 480239ed2e343df560ec80b467500beee838360c
parent 6fb7dc2055f63d5dbf46a3ab6afa118a2c4d15f1
Author: Sebastian Gerhardt <sebgerhardt@gmx.net>
Date:   Wed, 13 Aug 2008 22:04:28 +0000

improved adherence to GNU coding standards (Hello, Browser-example)


Diffstat:
Mdoc/examples/hellobrowser.c | 17+++++++++--------
Mdoc/hellobrowser.inc | 24+++++++++++++-----------
2 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/doc/examples/hellobrowser.c b/doc/examples/hellobrowser.c @@ -5,9 +5,9 @@ #define PORT 8888 -int AnswerToConnection(void *cls, struct MHD_Connection *connection, const char *url, - const char *method, const char *version, const char *upload_data, - unsigned int *upload_data_size, void **con_cls) +int answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, + const char *method, const char *version, const char *upload_data, + unsigned int *upload_data_size, void **con_cls) { const char *page = "<html><body>Hello, browser!</body></html>"; struct MHD_Response *response; @@ -16,6 +16,7 @@ int AnswerToConnection(void *cls, struct MHD_Connection *connection, const char 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; } @@ -23,12 +24,12 @@ int main () { struct MHD_Daemon *daemon; - daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL, - &AnswerToConnection, NULL, MHD_OPTION_END); - if (daemon == NULL) return 1; + daemon = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL, + &answer_to_connection, NULL, MHD_OPTION_END); + if (NULL == daemon) return 1; - getchar(); + getchar (); - MHD_stop_daemon(daemon); + MHD_stop_daemon (daemon); return 0; } diff --git a/doc/hellobrowser.inc b/doc/hellobrowser.inc @@ -35,9 +35,9 @@ daemon to sent the reply. Talking about the reply, it is defined as a string right after the function header @verbatim -int AnswerToConnection(void *cls, struct MHD_Connection *connection, - const char *url, const char *method, const char *version, - const char *upload_data, unsigned int *upload_data_size, void **con_cls) +int answer_to_connection (void *cls, struct MHD_Connection *connection, const char *url, + const char *method, const char *version, const char *upload_data, + unsigned int *upload_data_size, void **con_cls) { const char *page = "<html><body>Hello, browser!</body></html>"; @end verbatim @@ -55,8 +55,8 @@ no internal copy to be done because the @emph{constant} string won't change anyw struct MHD_Response *response; int ret; - response = MHD_create_response_from_data(strlen(page), - (void*)page, MHD_NO, MHD_NO); + response = MHD_create_response_from_data (strlen (page), + (void*) page, MHD_NO, MHD_NO); @end verbatim @noindent Now that the the response has been laced up, it is ready for delivery and can be queued for sending. @@ -72,6 +72,7 @@ already being set at this point to either MHD_YES or MHD_NO in case of success o @verbatim ret = MHD_queue_response (connection, MHD_HTTP_OK, response); MHD_destroy_response (response); + return ret; } @end verbatim @@ -81,11 +82,11 @@ on @code{PORT} for connections. This is done in the main function. @verbatim int main () { - struct MHD_Daemon *d; + struct MHD_Daemon *daemon; - d = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL, - &AnswerToConnection, NULL, MHD_OPTION_END); - if (d == NULL) return 1; + daemon = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY, PORT, NULL, NULL, + &answer_to_connection, NULL, MHD_OPTION_END); + if (NULL == daemon) return 1; @end verbatim @noindent The first parameter is one of three possible modes of operation. Here we want the daemon to run in @@ -107,11 +108,12 @@ main thread or else the program will terminate prematurely. We let it pause in a friendly manner by waiting for the enter key to be pressed. In the end, we stop the daemon so it can do its cleanup tasks. @verbatim - getchar(); + getchar (); - MHD_stop_daemon(d); + MHD_stop_daemon (daemon); return 0; } + @end verbatim @noindent The first example is now complete.