diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-12-05 16:30:51 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-12-05 16:30:51 +0000 |
commit | 8b0e534ac401da8187e67568e392d7635bf0c747 (patch) | |
tree | 038fa42bba57831fa7880d74d937b1187a7c3a6b /src/examples | |
parent | c4448622ca947316434cc1e340a56aa411bc0ad4 (diff) | |
download | libmicrohttpd-8b0e534ac401da8187e67568e392d7635bf0c747.tar.gz libmicrohttpd-8b0e534ac401da8187e67568e392d7635bf0c747.zip |
add timeout example
Diffstat (limited to 'src/examples')
-rw-r--r-- | src/examples/Makefile.am | 10 | ||||
-rw-r--r-- | src/examples/timeout.c | 50 |
2 files changed, 57 insertions, 3 deletions
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am index c3330e6f..495ab52e 100644 --- a/src/examples/Makefile.am +++ b/src/examples/Makefile.am | |||
@@ -23,10 +23,11 @@ noinst_PROGRAMS = \ | |||
23 | dual_stack_example \ | 23 | dual_stack_example \ |
24 | minimal_example_comet \ | 24 | minimal_example_comet \ |
25 | querystring_example \ | 25 | querystring_example \ |
26 | timeout \ | ||
26 | fileserver_example \ | 27 | fileserver_example \ |
27 | fileserver_example_dirs \ | 28 | fileserver_example_dirs \ |
28 | fileserver_example_external_select \ | 29 | fileserver_example_external_select \ |
29 | refuse_post_example | 30 | refuse_post_example |
30 | 31 | ||
31 | 32 | ||
32 | if ENABLE_HTTPS | 33 | if ENABLE_HTTPS |
@@ -61,6 +62,11 @@ minimal_example_SOURCES = \ | |||
61 | minimal_example_LDADD = \ | 62 | minimal_example_LDADD = \ |
62 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 63 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
63 | 64 | ||
65 | timeout_SOURCES = \ | ||
66 | timeout.c | ||
67 | timeout_LDADD = \ | ||
68 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | ||
69 | |||
64 | chunked_example_SOURCES = \ | 70 | chunked_example_SOURCES = \ |
65 | chunked_example.c | 71 | chunked_example.c |
66 | chunked_example_LDADD = \ | 72 | chunked_example_LDADD = \ |
@@ -156,5 +162,3 @@ https_fileserver_example_CPPFLAGS = \ | |||
156 | $(AM_CPPFLAGS) $(GNUTLS_CPPFLAGS) | 162 | $(AM_CPPFLAGS) $(GNUTLS_CPPFLAGS) |
157 | https_fileserver_example_LDADD = \ | 163 | https_fileserver_example_LDADD = \ |
158 | $(top_builddir)/src/microhttpd/libmicrohttpd.la | 164 | $(top_builddir)/src/microhttpd/libmicrohttpd.la |
159 | |||
160 | |||
diff --git a/src/examples/timeout.c b/src/examples/timeout.c new file mode 100644 index 00000000..51571371 --- /dev/null +++ b/src/examples/timeout.c | |||
@@ -0,0 +1,50 @@ | |||
1 | #include <microhttpd.h> | ||
2 | #include <stdio.h> | ||
3 | #include <string.h> | ||
4 | |||
5 | #define PORT 8080 | ||
6 | |||
7 | static int | ||
8 | answer_to_connection(void *cls, | ||
9 | struct MHD_Connection *connection, | ||
10 | const char *url, | ||
11 | const char *method, | ||
12 | const char *version, | ||
13 | const char *upload_data, | ||
14 | size_t *upload_data_size, | ||
15 | void **con_cls) | ||
16 | { | ||
17 | const char *page = "<html><body>Hello world!</body></html>"; | ||
18 | struct MHD_Response *response; | ||
19 | int ret; | ||
20 | |||
21 | response = MHD_create_response_from_buffer (strlen(page), | ||
22 | (void *) page, | ||
23 | MHD_RESPMEM_PERSISTENT); | ||
24 | MHD_add_response_header(response, | ||
25 | MHD_HTTP_HEADER_CONTENT_TYPE, | ||
26 | "text/html"); | ||
27 | ret = MHD_queue_response (connection, | ||
28 | MHD_HTTP_OK, | ||
29 | response); | ||
30 | MHD_destroy_response(response); | ||
31 | return ret; | ||
32 | } | ||
33 | |||
34 | |||
35 | int main() | ||
36 | { | ||
37 | struct MHD_Daemon *daemon; | ||
38 | |||
39 | daemon = MHD_start_daemon(// MHD_USE_SELECT_INTERNALLY | | ||
40 | MHD_USE_THREAD_PER_CONNECTION, // if you comment this line, the problem dies | ||
41 | PORT, NULL, NULL, | ||
42 | &answer_to_connection, NULL, | ||
43 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 3, | ||
44 | MHD_OPTION_END); | ||
45 | if (NULL == daemon) | ||
46 | return 1; | ||
47 | getchar(); | ||
48 | MHD_stop_daemon(daemon); | ||
49 | return 0; | ||
50 | } | ||