diff options
author | Andrey Uzunov <andrey.uzunov@gmail.com> | 2013-08-28 22:43:31 +0000 |
---|---|---|
committer | Andrey Uzunov <andrey.uzunov@gmail.com> | 2013-08-28 22:43:31 +0000 |
commit | 02171fdaeb0c1e02f778cd1e595319fd63941b8e (patch) | |
tree | 0c3c5509a193d8ee702654f57d466a88346cbd7b | |
parent | eb34a0239f3d63fd2c04401bf341aacf38a141e3 (diff) | |
download | libmicrohttpd-02171fdaeb0c1e02f778cd1e595319fd63941b8e.tar.gz libmicrohttpd-02171fdaeb0c1e02f778cd1e595319fd63941b8e.zip |
mhd2spdy: changes to use MHDs request completed callback
-rw-r--r-- | src/examples/mhd2spdy.c | 5 | ||||
-rw-r--r-- | src/examples/mhd2spdy_http.c | 59 | ||||
-rw-r--r-- | src/examples/mhd2spdy_http.h | 8 | ||||
-rw-r--r-- | src/examples/mhd2spdy_spdy.c | 16 | ||||
-rw-r--r-- | src/examples/mhd2spdy_structures.h | 3 |
5 files changed, 66 insertions, 25 deletions
diff --git a/src/examples/mhd2spdy.c b/src/examples/mhd2spdy.c index 01a8c7a3..e44d3269 100644 --- a/src/examples/mhd2spdy.c +++ b/src/examples/mhd2spdy.c | |||
@@ -114,7 +114,8 @@ run_everything () | |||
114 | MHD_SUPPRESS_DATE_NO_CLOCK, | 114 | MHD_SUPPRESS_DATE_NO_CLOCK, |
115 | glob_opt.listen_port, | 115 | glob_opt.listen_port, |
116 | NULL, NULL, &http_cb_request, NULL, | 116 | NULL, NULL, &http_cb_request, NULL, |
117 | MHD_OPTION_URI_LOG_CALLBACK, &http_log_cb, NULL, | 117 | MHD_OPTION_URI_LOG_CALLBACK, &http_cb_log, NULL, |
118 | MHD_OPTION_NOTIFY_COMPLETED, &http_cb_request_completed, NULL, | ||
118 | MHD_OPTION_END); | 119 | MHD_OPTION_END); |
119 | if(NULL==daemon) | 120 | if(NULL==daemon) |
120 | DIE("MHD_start_daemon failed"); | 121 | DIE("MHD_start_daemon failed"); |
@@ -175,7 +176,7 @@ run_everything () | |||
175 | PRINT_INFO2("select error: %i", errno); | 176 | PRINT_INFO2("select error: %i", errno); |
176 | break; | 177 | break; |
177 | case 0: | 178 | case 0: |
178 | break; | 179 | //break; |
179 | default: | 180 | default: |
180 | PRINT_INFO("run"); | 181 | PRINT_INFO("run"); |
181 | //MHD_run_from_select(daemon,&rs, &ws, &es); //not closing FDs at some time in past | 182 | //MHD_run_from_select(daemon,&rs, &ws, &es); //not closing FDs at some time in past |
diff --git a/src/examples/mhd2spdy_http.c b/src/examples/mhd2spdy_http.c index 1f7dec97..cf9f6c52 100644 --- a/src/examples/mhd2spdy_http.c +++ b/src/examples/mhd2spdy_http.c | |||
@@ -27,7 +27,7 @@ | |||
27 | 27 | ||
28 | 28 | ||
29 | void * | 29 | void * |
30 | http_log_cb(void * cls, | 30 | http_cb_log(void * cls, |
31 | const char * uri) | 31 | const char * uri) |
32 | { | 32 | { |
33 | (void)cls; | 33 | (void)cls; |
@@ -45,7 +45,7 @@ const char * uri) | |||
45 | 45 | ||
46 | 46 | ||
47 | static int | 47 | static int |
48 | http_iterate_cb(void *cls, | 48 | http_cb_iterate(void *cls, |
49 | enum MHD_ValueKind kind, | 49 | enum MHD_ValueKind kind, |
50 | const char *name, | 50 | const char *name, |
51 | const char *value) | 51 | const char *value) |
@@ -76,7 +76,7 @@ http_iterate_cb(void *cls, | |||
76 | 76 | ||
77 | 77 | ||
78 | static ssize_t | 78 | static ssize_t |
79 | http_response_callback (void *cls, | 79 | http_cb_response (void *cls, |
80 | uint64_t pos, | 80 | uint64_t pos, |
81 | char *buffer, | 81 | char *buffer, |
82 | size_t max) | 82 | size_t max) |
@@ -89,9 +89,9 @@ http_response_callback (void *cls, | |||
89 | const union MHD_ConnectionInfo *info; | 89 | const union MHD_ConnectionInfo *info; |
90 | int val = 1; | 90 | int val = 1; |
91 | 91 | ||
92 | PRINT_INFO2("http_response_callback for %s", proxy->url); | 92 | PRINT_INFO2("http_cb_response for %s", proxy->url); |
93 | 93 | ||
94 | if(proxy->error) | 94 | if(proxy->spdy_error) |
95 | return MHD_CONTENT_READER_END_WITH_ERROR; | 95 | return MHD_CONTENT_READER_END_WITH_ERROR; |
96 | 96 | ||
97 | if(0 == proxy->http_body_size &&( proxy->done || !proxy->spdy_active)){ | 97 | if(0 == proxy->http_body_size &&( proxy->done || !proxy->spdy_active)){ |
@@ -145,18 +145,15 @@ http_response_callback (void *cls, | |||
145 | 145 | ||
146 | 146 | ||
147 | static void | 147 | static void |
148 | http_response_done_callback(void *cls) | 148 | http_cb_response_done(void *cls) |
149 | { | 149 | { |
150 | struct Proxy *proxy = (struct Proxy *)cls; | ||
151 | 150 | ||
152 | PRINT_INFO2("http_response_done_callback for %s", proxy->url); | 151 | //TODO |
152 | /*struct Proxy *proxy = (struct Proxy *)cls; | ||
153 | 153 | ||
154 | if(proxy->spdy_active) | 154 | PRINT_INFO2("http_cb_response_done for %s", proxy->url); |
155 | proxy->http_active = false; | 155 | */ |
156 | else | ||
157 | free_proxy(proxy); | ||
158 | 156 | ||
159 | --glob_opt.responses_pending; | ||
160 | } | 157 | } |
161 | 158 | ||
162 | int | 159 | int |
@@ -291,7 +288,7 @@ http_cb_request (void *cls, | |||
291 | spdy_headers.cnt = 10; | 288 | spdy_headers.cnt = 10; |
292 | MHD_get_connection_values (connection, | 289 | MHD_get_connection_values (connection, |
293 | MHD_HEADER_KIND, | 290 | MHD_HEADER_KIND, |
294 | &http_iterate_cb, | 291 | &http_cb_iterate, |
295 | &spdy_headers); | 292 | &spdy_headers); |
296 | 293 | ||
297 | spdy_headers.nv[spdy_headers.cnt] = NULL; | 294 | spdy_headers.nv[spdy_headers.cnt] = NULL; |
@@ -309,9 +306,9 @@ http_cb_request (void *cls, | |||
309 | 306 | ||
310 | proxy->http_response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, | 307 | proxy->http_response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, |
311 | 4096, | 308 | 4096, |
312 | &http_response_callback, | 309 | &http_cb_response, |
313 | proxy, | 310 | proxy, |
314 | &http_response_done_callback); | 311 | &http_cb_response_done); |
315 | 312 | ||
316 | if (proxy->http_response == NULL) | 313 | if (proxy->http_response == NULL) |
317 | DIE("no response"); | 314 | DIE("no response"); |
@@ -371,3 +368,33 @@ http_create_response(struct Proxy* proxy, | |||
371 | 368 | ||
372 | MHD_destroy_response (proxy->http_response); | 369 | MHD_destroy_response (proxy->http_response); |
373 | } | 370 | } |
371 | |||
372 | void | ||
373 | http_cb_request_completed (void *cls, | ||
374 | struct MHD_Connection *connection, | ||
375 | void **con_cls, | ||
376 | enum MHD_RequestTerminationCode toe) | ||
377 | { | ||
378 | struct HTTP_URI *http_uri = (struct HTTP_URI *)*con_cls; | ||
379 | if(NULL == http_uri) return; | ||
380 | struct Proxy *proxy = (struct Proxy *)http_uri->proxy; | ||
381 | |||
382 | PRINT_INFO2("http_cb_request_completed %i for %s",toe, http_uri->uri); | ||
383 | |||
384 | if(proxy->spdy_active) | ||
385 | { | ||
386 | proxy->http_active = false; | ||
387 | if(MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) | ||
388 | { | ||
389 | proxy->http_error = true; | ||
390 | assert(proxy->stream_id > 0); | ||
391 | //send RST_STREAM_STATUS_CANCEL | ||
392 | PRINT_INFO("send rst_stream" ); | ||
393 | spdylay_submit_rst_stream(proxy->spdy_connection->session, proxy->stream_id, 5); | ||
394 | } | ||
395 | } | ||
396 | else | ||
397 | free_proxy(proxy); | ||
398 | |||
399 | --glob_opt.responses_pending; | ||
400 | } | ||
diff --git a/src/examples/mhd2spdy_http.h b/src/examples/mhd2spdy_http.h index 240959cf..7abfb14c 100644 --- a/src/examples/mhd2spdy_http.h +++ b/src/examples/mhd2spdy_http.h | |||
@@ -38,11 +38,17 @@ http_cb_request (void *cls, | |||
38 | void **ptr); | 38 | void **ptr); |
39 | 39 | ||
40 | 40 | ||
41 | void * http_log_cb(void * cls, const char * uri); | 41 | void * http_cb_log(void * cls, const char * uri); |
42 | 42 | ||
43 | 43 | ||
44 | void | 44 | void |
45 | http_create_response(struct Proxy* proxy, char **nv); | 45 | http_create_response(struct Proxy* proxy, char **nv); |
46 | 46 | ||
47 | 47 | ||
48 | void | ||
49 | http_cb_request_completed (void *cls, | ||
50 | struct MHD_Connection *connection, | ||
51 | void **con_cls, | ||
52 | enum MHD_RequestTerminationCode toe); | ||
53 | |||
48 | #endif | 54 | #endif |
diff --git a/src/examples/mhd2spdy_spdy.c b/src/examples/mhd2spdy_spdy.c index 2c06ef88..2bc87976 100644 --- a/src/examples/mhd2spdy_spdy.c +++ b/src/examples/mhd2spdy_spdy.c | |||
@@ -334,7 +334,7 @@ spdy_cb_on_ctrl_recv(spdylay_session *session, | |||
334 | break; | 334 | break; |
335 | case SPDYLAY_RST_STREAM: | 335 | case SPDYLAY_RST_STREAM: |
336 | PRINT_INFO2("received reset stream for %s", proxy->url); | 336 | PRINT_INFO2("received reset stream for %s", proxy->url); |
337 | proxy->error = true; | 337 | proxy->spdy_error = true; |
338 | break; | 338 | break; |
339 | case SPDYLAY_HEADERS: | 339 | case SPDYLAY_HEADERS: |
340 | PRINT_INFO2("received headers for %s", proxy->url); | 340 | PRINT_INFO2("received headers for %s", proxy->url); |
@@ -398,7 +398,13 @@ spdy_cb_on_data_chunk_recv(spdylay_session *session, | |||
398 | 398 | ||
399 | struct Proxy *proxy; | 399 | struct Proxy *proxy; |
400 | proxy = spdylay_session_get_stream_user_data(session, stream_id); | 400 | proxy = spdylay_session_get_stream_user_data(session, stream_id); |
401 | 401 | ||
402 | if(NULL == proxy) | ||
403 | { | ||
404 | PRINT_INFO("proxy in spdy_cb_on_data_chunk_recv is NULL)"); | ||
405 | return; | ||
406 | } | ||
407 | |||
402 | if(!copy_buffer(data, len, &proxy->http_body, &proxy->http_body_size)) | 408 | if(!copy_buffer(data, len, &proxy->http_body, &proxy->http_body_size)) |
403 | { | 409 | { |
404 | //TODO handle it better? | 410 | //TODO handle it better? |
@@ -1076,9 +1082,9 @@ spdy_run_select(fd_set * read_fd_set, | |||
1076 | else | 1082 | else |
1077 | { | 1083 | { |
1078 | PRINT_INFO("not called"); | 1084 | PRINT_INFO("not called"); |
1079 | PRINT_INFO2("connection->want_io %i",connections[i]->want_io); | 1085 | //PRINT_INFO2("connection->want_io %i",connections[i]->want_io); |
1080 | PRINT_INFO2("read %i",spdylay_session_want_read(connections[i]->session)); | 1086 | //PRINT_INFO2("read %i",spdylay_session_want_read(connections[i]->session)); |
1081 | PRINT_INFO2("write %i",spdylay_session_want_write(connections[i]->session)); | 1087 | //PRINT_INFO2("write %i",spdylay_session_want_write(connections[i]->session)); |
1082 | //raise(SIGINT); | 1088 | //raise(SIGINT); |
1083 | } | 1089 | } |
1084 | } | 1090 | } |
diff --git a/src/examples/mhd2spdy_structures.h b/src/examples/mhd2spdy_structures.h index c9aa4c39..ad75e0cc 100644 --- a/src/examples/mhd2spdy_structures.h +++ b/src/examples/mhd2spdy_structures.h | |||
@@ -120,7 +120,8 @@ struct Proxy | |||
120 | int id; | 120 | int id; |
121 | int32_t stream_id; | 121 | int32_t stream_id; |
122 | bool done; | 122 | bool done; |
123 | bool error; | 123 | bool http_error; |
124 | bool spdy_error; | ||
124 | bool http_active; | 125 | bool http_active; |
125 | bool spdy_active; | 126 | bool spdy_active; |
126 | bool receiving_done; | 127 | bool receiving_done; |