diff options
Diffstat (limited to 'src/examples/connection_close.c')
-rw-r--r-- | src/examples/connection_close.c | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/src/examples/connection_close.c b/src/examples/connection_close.c index 88222cbf..43ee379f 100644 --- a/src/examples/connection_close.c +++ b/src/examples/connection_close.c | |||
@@ -25,7 +25,8 @@ | |||
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include <microhttpd.h> | 26 | #include <microhttpd.h> |
27 | 27 | ||
28 | #define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" | 28 | #define PAGE \ |
29 | "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" | ||
29 | 30 | ||
30 | static int | 31 | static int |
31 | ahc_echo (void *cls, | 32 | ahc_echo (void *cls, |
@@ -39,23 +40,23 @@ ahc_echo (void *cls, | |||
39 | const char *me = cls; | 40 | const char *me = cls; |
40 | struct MHD_Response *response; | 41 | struct MHD_Response *response; |
41 | int ret; | 42 | int ret; |
42 | (void)url; /* Unused. Silent compiler warning. */ | 43 | (void) url; /* Unused. Silent compiler warning. */ |
43 | (void)version; /* Unused. Silent compiler warning. */ | 44 | (void) version; /* Unused. Silent compiler warning. */ |
44 | (void)upload_data; /* Unused. Silent compiler warning. */ | 45 | (void) upload_data; /* Unused. Silent compiler warning. */ |
45 | (void)upload_data_size; /* Unused. Silent compiler warning. */ | 46 | (void) upload_data_size; /* Unused. Silent compiler warning. */ |
46 | 47 | ||
47 | if (0 != strcmp (method, "GET")) | 48 | if (0 != strcmp (method, "GET")) |
48 | return MHD_NO; /* unexpected method */ | 49 | return MHD_NO; /* unexpected method */ |
49 | if (&aptr != *ptr) | 50 | if (&aptr != *ptr) |
50 | { | 51 | { |
51 | /* do never respond on first call */ | 52 | /* do never respond on first call */ |
52 | *ptr = &aptr; | 53 | *ptr = &aptr; |
53 | return MHD_YES; | 54 | return MHD_YES; |
54 | } | 55 | } |
55 | *ptr = NULL; /* reset when done */ | 56 | *ptr = NULL; /* reset when done */ |
56 | response = MHD_create_response_from_buffer (strlen (me), | 57 | response = MHD_create_response_from_buffer (strlen (me), |
57 | (void *) me, | 58 | (void *) me, |
58 | MHD_RESPMEM_PERSISTENT); | 59 | MHD_RESPMEM_PERSISTENT); |
59 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 60 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
60 | MHD_destroy_response (response); | 61 | MHD_destroy_response (response); |
61 | return ret; | 62 | return ret; |
@@ -65,27 +66,27 @@ ahc_echo (void *cls, | |||
65 | 66 | ||
66 | static void | 67 | static void |
67 | request_completed (void *cls, | 68 | request_completed (void *cls, |
68 | struct MHD_Connection *connection, | 69 | struct MHD_Connection *connection, |
69 | void **con_cls, | 70 | void **con_cls, |
70 | enum MHD_RequestTerminationCode toe) | 71 | enum MHD_RequestTerminationCode toe) |
71 | { | 72 | { |
72 | fprintf (stderr, | 73 | fprintf (stderr, |
73 | "%llu - RC: %d\n", | 74 | "%llu - RC: %d\n", |
74 | (unsigned long long) __rdtsc(), | 75 | (unsigned long long) __rdtsc (), |
75 | toe); | 76 | toe); |
76 | } | 77 | } |
77 | 78 | ||
78 | 79 | ||
79 | static void | 80 | static void |
80 | connection_completed (void *cls, | 81 | connection_completed (void *cls, |
81 | struct MHD_Connection *connection, | 82 | struct MHD_Connection *connection, |
82 | void **socket_context, | 83 | void **socket_context, |
83 | enum MHD_ConnectionNotificationCode toe) | 84 | enum MHD_ConnectionNotificationCode toe) |
84 | { | 85 | { |
85 | fprintf (stderr, | 86 | fprintf (stderr, |
86 | "%llu - CC: %d\n", | 87 | "%llu - CC: %d\n", |
87 | (unsigned long long) __rdtsc(), | 88 | (unsigned long long) __rdtsc (), |
88 | toe); | 89 | toe); |
89 | } | 90 | } |
90 | 91 | ||
91 | 92 | ||
@@ -95,22 +96,23 @@ main (int argc, char *const *argv) | |||
95 | struct MHD_Daemon *d; | 96 | struct MHD_Daemon *d; |
96 | 97 | ||
97 | if (argc != 2) | 98 | if (argc != 2) |
98 | { | 99 | { |
99 | printf ("%s PORT\n", argv[0]); | 100 | printf ("%s PORT\n", argv[0]); |
100 | return 1; | 101 | return 1; |
101 | } | 102 | } |
102 | d = MHD_start_daemon (/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ | 103 | d = MHD_start_daemon (/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ |
103 | /* MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ | 104 | /* MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ |
104 | /* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */ | 105 | /* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */ |
105 | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, // | MHD_USE_ITC, | 106 | MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD |
106 | /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ | 107 | | MHD_USE_ERROR_LOG | MHD_USE_POLL, // | MHD_USE_ITC, |
107 | atoi (argv[1]), | 108 | /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */ |
108 | NULL, NULL, &ahc_echo, PAGE, | 109 | atoi (argv[1]), |
109 | MHD_OPTION_NOTIFY_COMPLETED, &request_completed, NULL, | 110 | NULL, NULL, &ahc_echo, PAGE, |
110 | MHD_OPTION_NOTIFY_CONNECTION, &connection_completed, NULL, | 111 | MHD_OPTION_NOTIFY_COMPLETED, &request_completed, NULL, |
111 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, | 112 | MHD_OPTION_NOTIFY_CONNECTION, &connection_completed, NULL, |
112 | MHD_OPTION_STRICT_FOR_CLIENT, (int) 1, | 113 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, |
113 | MHD_OPTION_END); | 114 | MHD_OPTION_STRICT_FOR_CLIENT, (int) 1, |
115 | MHD_OPTION_END); | ||
114 | if (d == NULL) | 116 | if (d == NULL) |
115 | return 1; | 117 | return 1; |
116 | (void) getc (stdin); | 118 | (void) getc (stdin); |