diff options
Diffstat (limited to 'src/testcurl/test_quiesce_stream.c')
-rw-r--r-- | src/testcurl/test_quiesce_stream.c | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/src/testcurl/test_quiesce_stream.c b/src/testcurl/test_quiesce_stream.c index bccb5890..821f1102 100644 --- a/src/testcurl/test_quiesce_stream.c +++ b/src/testcurl/test_quiesce_stream.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #include <unistd.h> | 35 | #include <unistd.h> |
36 | #elif defined(_WIN32) | 36 | #elif defined(_WIN32) |
37 | #include <windows.h> | 37 | #include <windows.h> |
38 | #define sleep(s) (Sleep((s)*1000), 0) | 38 | #define sleep(s) (Sleep ((s) * 1000), 0) |
39 | #endif /* _WIN32 */ | 39 | #endif /* _WIN32 */ |
40 | 40 | ||
41 | 41 | ||
@@ -48,8 +48,8 @@ http_PanicCallback (void *cls, | |||
48 | unsigned int line, | 48 | unsigned int line, |
49 | const char *reason) | 49 | const char *reason) |
50 | { | 50 | { |
51 | (void)cls; /* Unused. Silent compiler warning. */ | 51 | (void) cls; /* Unused. Silent compiler warning. */ |
52 | fprintf( stderr, | 52 | fprintf (stderr, |
53 | "PANIC: exit process: %s at %s:%u\n", | 53 | "PANIC: exit process: %s at %s:%u\n", |
54 | reason, | 54 | reason, |
55 | file, | 55 | file, |
@@ -81,11 +81,11 @@ suspend_connection (struct MHD_Connection *connection) | |||
81 | &resume_connection, | 81 | &resume_connection, |
82 | connection); | 82 | connection); |
83 | if (0 != status) | 83 | if (0 != status) |
84 | { | 84 | { |
85 | fprintf (stderr, | 85 | fprintf (stderr, |
86 | "Could not create thead\n"); | 86 | "Could not create thead\n"); |
87 | exit( EXIT_FAILURE ); | 87 | exit (EXIT_FAILURE); |
88 | } | 88 | } |
89 | pthread_detach (thread_id); | 89 | pthread_detach (thread_id); |
90 | } | 90 | } |
91 | 91 | ||
@@ -103,17 +103,18 @@ http_ContentReaderCallback (void *cls, | |||
103 | char *buf, | 103 | char *buf, |
104 | size_t max) | 104 | size_t max) |
105 | { | 105 | { |
106 | static const char alphabet[] = "\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | 106 | static const char alphabet[] = |
107 | "\nABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
107 | struct ContentReaderUserdata *userdata = cls; | 108 | struct ContentReaderUserdata *userdata = cls; |
108 | (void)pos;(void)max; /* Unused. Silent compiler warning. */ | 109 | (void) pos; (void) max; /* Unused. Silent compiler warning. */ |
109 | 110 | ||
110 | if( userdata->bytes_written >= 1024) | 111 | if ( userdata->bytes_written >= 1024) |
111 | { | 112 | { |
112 | fprintf( stderr, | 113 | fprintf (stderr, |
113 | "finish: %d\n", | 114 | "finish: %d\n", |
114 | request_counter); | 115 | request_counter); |
115 | return MHD_CONTENT_READER_END_OF_STREAM; | 116 | return MHD_CONTENT_READER_END_OF_STREAM; |
116 | } | 117 | } |
117 | userdata->bytes_written++; | 118 | userdata->bytes_written++; |
118 | buf[0] = alphabet[userdata->bytes_written % (sizeof(alphabet) - 1)]; | 119 | buf[0] = alphabet[userdata->bytes_written % (sizeof(alphabet) - 1)]; |
119 | suspend_connection (userdata->connection); | 120 | suspend_connection (userdata->connection); |
@@ -139,21 +140,22 @@ http_AccessHandlerCallback (void *cls, | |||
139 | const char *version, | 140 | const char *version, |
140 | const char *upload_data, | 141 | const char *upload_data, |
141 | size_t *upload_data_size, | 142 | size_t *upload_data_size, |
142 | void **con_cls ) | 143 | void **con_cls) |
143 | { | 144 | { |
144 | int ret; | 145 | int ret; |
145 | (void)cls;(void)url; /* Unused. Silent compiler warning. */ | 146 | (void) cls; (void) url; /* Unused. Silent compiler warning. */ |
146 | (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler warning. */ | 147 | (void) method; (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ |
147 | (void)upload_data_size; /* Unused. Silent compiler warning. */ | 148 | (void) upload_data_size; /* Unused. Silent compiler warning. */ |
148 | 149 | ||
149 | /* Never respond on first call */ | 150 | /* Never respond on first call */ |
150 | if (NULL == *con_cls) | 151 | if (NULL == *con_cls) |
151 | { | 152 | { |
152 | fprintf (stderr, | 153 | fprintf (stderr, |
153 | "start: %d\n", | 154 | "start: %d\n", |
154 | ++request_counter); | 155 | ++request_counter); |
155 | 156 | ||
156 | struct ContentReaderUserdata *userdata = malloc (sizeof(struct ContentReaderUserdata)); | 157 | struct ContentReaderUserdata *userdata = malloc (sizeof(struct |
158 | ContentReaderUserdata)); | ||
157 | 159 | ||
158 | if (NULL == userdata) | 160 | if (NULL == userdata) |
159 | return MHD_NO; | 161 | return MHD_NO; |
@@ -181,7 +183,7 @@ http_AccessHandlerCallback (void *cls, | |||
181 | 183 | ||
182 | 184 | ||
183 | int | 185 | int |
184 | main(void) | 186 | main (void) |
185 | { | 187 | { |
186 | int port; | 188 | int port; |
187 | char command_line[1024]; | 189 | char command_line[1024]; |
@@ -198,9 +200,9 @@ main(void) | |||
198 | /* Flags */ | 200 | /* Flags */ |
199 | unsigned int daemon_flags | 201 | unsigned int daemon_flags |
200 | = MHD_USE_INTERNAL_POLLING_THREAD | 202 | = MHD_USE_INTERNAL_POLLING_THREAD |
201 | | MHD_USE_AUTO | 203 | | MHD_USE_AUTO |
202 | | MHD_ALLOW_SUSPEND_RESUME | 204 | | MHD_ALLOW_SUSPEND_RESUME |
203 | | MHD_USE_ITC; | 205 | | MHD_USE_ITC; |
204 | 206 | ||
205 | /* Create daemon */ | 207 | /* Create daemon */ |
206 | struct MHD_Daemon *daemon = MHD_start_daemon (daemon_flags, | 208 | struct MHD_Daemon *daemon = MHD_start_daemon (daemon_flags, |
@@ -213,33 +215,35 @@ main(void) | |||
213 | if (NULL == daemon) | 215 | if (NULL == daemon) |
214 | return 1; | 216 | return 1; |
215 | if (0 == port) | 217 | if (0 == port) |
218 | { | ||
219 | const union MHD_DaemonInfo *dinfo; | ||
220 | dinfo = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT); | ||
221 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
216 | { | 222 | { |
217 | const union MHD_DaemonInfo *dinfo; | 223 | MHD_stop_daemon (daemon); return 32; |
218 | dinfo = MHD_get_daemon_info (daemon, MHD_DAEMON_INFO_BIND_PORT); | ||
219 | if (NULL == dinfo || 0 == dinfo->port) | ||
220 | { MHD_stop_daemon (daemon); return 32; } | ||
221 | port = (int)dinfo->port; | ||
222 | } | 224 | } |
225 | port = (int) dinfo->port; | ||
226 | } | ||
223 | snprintf (command_line, | 227 | snprintf (command_line, |
224 | sizeof (command_line), | 228 | sizeof (command_line), |
225 | "curl -s http://127.0.0.1:%d", | 229 | "curl -s http://127.0.0.1:%d", |
226 | port); | 230 | port); |
227 | 231 | ||
228 | if (0 != system (command_line)) | 232 | if (0 != system (command_line)) |
229 | { | 233 | { |
230 | MHD_stop_daemon (daemon); | 234 | MHD_stop_daemon (daemon); |
231 | return 1; | 235 | return 1; |
232 | } | 236 | } |
233 | /* wait for a request */ | 237 | /* wait for a request */ |
234 | while (0 == request_counter) | 238 | while (0 == request_counter) |
235 | (void)sleep (1); | 239 | (void) sleep (1); |
236 | 240 | ||
237 | fprintf (stderr, | 241 | fprintf (stderr, |
238 | "quiesce\n"); | 242 | "quiesce\n"); |
239 | MHD_quiesce_daemon (daemon); | 243 | MHD_quiesce_daemon (daemon); |
240 | 244 | ||
241 | /* wait a second */ | 245 | /* wait a second */ |
242 | (void)sleep (1); | 246 | (void) sleep (1); |
243 | 247 | ||
244 | fprintf (stderr, | 248 | fprintf (stderr, |
245 | "stopping daemon\n"); | 249 | "stopping daemon\n"); |