aboutsummaryrefslogtreecommitdiff
path: root/src/examples/chunked_example.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/chunked_example.c')
-rw-r--r--src/examples/chunked_example.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/examples/chunked_example.c b/src/examples/chunked_example.c
index a661216c..9bf73e34 100644
--- a/src/examples/chunked_example.c
+++ b/src/examples/chunked_example.c
@@ -32,6 +32,7 @@ struct ResponseContentCallbackParam
32 size_t response_size; 32 size_t response_size;
33}; 33};
34 34
35
35static ssize_t 36static ssize_t
36callback (void *cls, 37callback (void *cls,
37 uint64_t pos, 38 uint64_t pos,
@@ -77,12 +78,14 @@ callback (void *cls,
77 return size_to_copy; 78 return size_to_copy;
78} 79}
79 80
80void 81
81free_callback_param(void *cls) 82static void
83free_callback_param (void *cls)
82{ 84{
83 free(cls); 85 free(cls);
84} 86}
85 87
88
86static const char simple_response_text[] = "<html><head><title>Simple response</title></head>" 89static const char simple_response_text[] = "<html><head><title>Simple response</title></head>"
87 "<body>Simple response text</body></html>"; 90 "<body>Simple response text</body></html>";
88 91
@@ -93,10 +96,12 @@ ahc_echo (void *cls,
93 const char *url, 96 const char *url,
94 const char *method, 97 const char *method,
95 const char *version, 98 const char *version,
96 const char *upload_data, size_t *upload_data_size, void **ptr) 99 const char *upload_data,
100 size_t *upload_data_size,
101 void **ptr)
97{ 102{
98 static int aptr; 103 static int aptr;
99 struct ResponseContentCallbackParam * callback_param; 104 struct ResponseContentCallbackParam *callback_param;
100 struct MHD_Response *response; 105 struct MHD_Response *response;
101 int ret; 106 int ret;
102 (void)cls; /* Unused. Silent compiler warning. */ 107 (void)cls; /* Unused. Silent compiler warning. */
@@ -127,31 +132,47 @@ ahc_echo (void *cls,
127 &callback, 132 &callback,
128 callback_param, 133 callback_param,
129 &free_callback_param); 134 &free_callback_param);
135 if (NULL == response)
136 {
137 free (callback_param);
138 return MHD_NO;
139 }
130 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 140 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
131 MHD_destroy_response (response); 141 MHD_destroy_response (response);
132 return ret; 142 return ret;
133} 143}
134 144
145
135int 146int
136main (int argc, char *const *argv) 147main (int argc, char *const *argv)
137{ 148{
138 struct MHD_Daemon *d; 149 struct MHD_Daemon *d;
150 int port;
139 151
140 if (argc != 2) 152 if (argc != 2)
141 { 153 {
142 printf ("%s PORT\n", argv[0]); 154 printf ("%s PORT\n", argv[0]);
143 return 1; 155 return 1;
144 } 156 }
157 port = atoi (argv[1]);
158 if ( (1 > port) ||
159 (port > UINT16_MAX) )
160 {
161 fprintf (stderr,
162 "Port must be a number between 1 and 65535\n");
163 return 1;
164 }
145 d = MHD_start_daemon (// MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 165 d = MHD_start_daemon (// MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
146 MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 166 MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
147 // MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, 167 // MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL,
148 // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, 168 // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL,
149 // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, 169 // MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
150 atoi (argv[1]), 170 (uint16_t) port,
151 NULL, NULL, &ahc_echo, NULL, 171 NULL, NULL,
172 &ahc_echo, NULL,
152 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, 173 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
153 MHD_OPTION_END); 174 MHD_OPTION_END);
154 if (d == NULL) 175 if (NULL == d)
155 return 1; 176 return 1;
156 (void) getc (stdin); 177 (void) getc (stdin);
157 MHD_stop_daemon (d); 178 MHD_stop_daemon (d);