diff options
Diffstat (limited to 'src/examples/minimal_example_empty.c')
-rw-r--r-- | src/examples/minimal_example_empty.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/examples/minimal_example_empty.c b/src/examples/minimal_example_empty.c new file mode 100644 index 00000000..2de1cc8b --- /dev/null +++ b/src/examples/minimal_example_empty.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | Copyright (C) 2007 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public | ||
16 | License along with this library; if not, write to the Free Software | ||
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
18 | */ | ||
19 | /** | ||
20 | * @file minimal_example.c | ||
21 | * @brief minimal example for how to use libmicrohttpd | ||
22 | * @author Christian Grothoff | ||
23 | */ | ||
24 | |||
25 | #include "platform.h" | ||
26 | #include <microhttpd.h> | ||
27 | |||
28 | |||
29 | static int | ||
30 | ahc_echo (void *cls, | ||
31 | struct MHD_Connection *connection, | ||
32 | const char *url, | ||
33 | const char *method, | ||
34 | const char *version, | ||
35 | const char *upload_data, | ||
36 | size_t *upload_data_size, | ||
37 | void **ptr) | ||
38 | { | ||
39 | static int aptr; | ||
40 | struct MHD_Response *response; | ||
41 | int ret; | ||
42 | |||
43 | (void) url; /* Unused. Silent compiler warning. */ | ||
44 | (void) version; /* Unused. Silent compiler warning. */ | ||
45 | (void) upload_data; /* Unused. Silent compiler warning. */ | ||
46 | (void) upload_data_size; /* Unused. Silent compiler warning. */ | ||
47 | |||
48 | if (0 != strcmp (method, "GET")) | ||
49 | return MHD_NO; /* unexpected method */ | ||
50 | if (&aptr != *ptr) | ||
51 | { | ||
52 | /* do never respond on first call */ | ||
53 | *ptr = &aptr; | ||
54 | return MHD_YES; | ||
55 | } | ||
56 | *ptr = NULL; /* reset when done */ | ||
57 | response = MHD_create_response_from_buffer (0, | ||
58 | NULL, | ||
59 | MHD_RESPMEM_PERSISTENT); | ||
60 | ret = MHD_queue_response (connection, | ||
61 | MHD_HTTP_NO_CONTENT, | ||
62 | response); | ||
63 | MHD_destroy_response (response); | ||
64 | return ret; | ||
65 | } | ||
66 | |||
67 | |||
68 | int | ||
69 | main (int argc, | ||
70 | char *const *argv) | ||
71 | { | ||
72 | struct MHD_Daemon *d; | ||
73 | |||
74 | if (argc != 2) | ||
75 | { | ||
76 | printf ("%s PORT\n", argv[0]); | ||
77 | return 1; | ||
78 | } | ||
79 | d = MHD_start_daemon (/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ | ||
80 | MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
81 | /* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */ | ||
82 | /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */ | ||
83 | /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ | ||
84 | atoi (argv[1]), | ||
85 | NULL, NULL, &ahc_echo, NULL, | ||
86 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, | ||
87 | MHD_OPTION_STRICT_FOR_CLIENT, (int) 1, | ||
88 | MHD_OPTION_END); | ||
89 | if (d == NULL) | ||
90 | return 1; | ||
91 | (void) getc (stdin); | ||
92 | MHD_stop_daemon (d); | ||
93 | return 0; | ||
94 | } | ||