libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 02171fdaeb0c1e02f778cd1e595319fd63941b8e
parent eb34a0239f3d63fd2c04401bf341aacf38a141e3
Author: Andrey Uzunov <andrey.uzunov@gmail.com>
Date:   Wed, 28 Aug 2013 22:43:31 +0000

mhd2spdy: changes to use MHDs request completed callback

Diffstat:
Msrc/examples/mhd2spdy.c | 5+++--
Msrc/examples/mhd2spdy_http.c | 59+++++++++++++++++++++++++++++++++++++++++++----------------
Msrc/examples/mhd2spdy_http.h | 8+++++++-
Msrc/examples/mhd2spdy_spdy.c | 16+++++++++++-----
Msrc/examples/mhd2spdy_structures.h | 3++-
5 files changed, 66 insertions(+), 25 deletions(-)

diff --git a/src/examples/mhd2spdy.c b/src/examples/mhd2spdy.c @@ -114,7 +114,8 @@ run_everything () MHD_SUPPRESS_DATE_NO_CLOCK, glob_opt.listen_port, NULL, NULL, &http_cb_request, NULL, - MHD_OPTION_URI_LOG_CALLBACK, &http_log_cb, NULL, + MHD_OPTION_URI_LOG_CALLBACK, &http_cb_log, NULL, + MHD_OPTION_NOTIFY_COMPLETED, &http_cb_request_completed, NULL, MHD_OPTION_END); if(NULL==daemon) DIE("MHD_start_daemon failed"); @@ -175,7 +176,7 @@ run_everything () PRINT_INFO2("select error: %i", errno); break; case 0: - break; + //break; default: PRINT_INFO("run"); //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 @@ -27,7 +27,7 @@ void * -http_log_cb(void * cls, +http_cb_log(void * cls, const char * uri) { (void)cls; @@ -45,7 +45,7 @@ const char * uri) static int -http_iterate_cb(void *cls, +http_cb_iterate(void *cls, enum MHD_ValueKind kind, const char *name, const char *value) @@ -76,7 +76,7 @@ http_iterate_cb(void *cls, static ssize_t -http_response_callback (void *cls, +http_cb_response (void *cls, uint64_t pos, char *buffer, size_t max) @@ -89,9 +89,9 @@ http_response_callback (void *cls, const union MHD_ConnectionInfo *info; int val = 1; - PRINT_INFO2("http_response_callback for %s", proxy->url); + PRINT_INFO2("http_cb_response for %s", proxy->url); - if(proxy->error) + if(proxy->spdy_error) return MHD_CONTENT_READER_END_WITH_ERROR; if(0 == proxy->http_body_size &&( proxy->done || !proxy->spdy_active)){ @@ -145,18 +145,15 @@ http_response_callback (void *cls, static void -http_response_done_callback(void *cls) +http_cb_response_done(void *cls) { - struct Proxy *proxy = (struct Proxy *)cls; - PRINT_INFO2("http_response_done_callback for %s", proxy->url); + //TODO + /*struct Proxy *proxy = (struct Proxy *)cls; - if(proxy->spdy_active) - proxy->http_active = false; - else - free_proxy(proxy); + PRINT_INFO2("http_cb_response_done for %s", proxy->url); + */ - --glob_opt.responses_pending; } int @@ -291,7 +288,7 @@ http_cb_request (void *cls, spdy_headers.cnt = 10; MHD_get_connection_values (connection, MHD_HEADER_KIND, - &http_iterate_cb, + &http_cb_iterate, &spdy_headers); spdy_headers.nv[spdy_headers.cnt] = NULL; @@ -309,9 +306,9 @@ http_cb_request (void *cls, proxy->http_response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 4096, - &http_response_callback, + &http_cb_response, proxy, - &http_response_done_callback); + &http_cb_response_done); if (proxy->http_response == NULL) DIE("no response"); @@ -371,3 +368,33 @@ http_create_response(struct Proxy* proxy, MHD_destroy_response (proxy->http_response); } + +void +http_cb_request_completed (void *cls, + struct MHD_Connection *connection, + void **con_cls, + enum MHD_RequestTerminationCode toe) +{ + struct HTTP_URI *http_uri = (struct HTTP_URI *)*con_cls; + if(NULL == http_uri) return; + struct Proxy *proxy = (struct Proxy *)http_uri->proxy; + + PRINT_INFO2("http_cb_request_completed %i for %s",toe, http_uri->uri); + + if(proxy->spdy_active) + { + proxy->http_active = false; + if(MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) + { + proxy->http_error = true; + assert(proxy->stream_id > 0); + //send RST_STREAM_STATUS_CANCEL + PRINT_INFO("send rst_stream" ); + spdylay_submit_rst_stream(proxy->spdy_connection->session, proxy->stream_id, 5); + } + } + else + free_proxy(proxy); + + --glob_opt.responses_pending; +} diff --git a/src/examples/mhd2spdy_http.h b/src/examples/mhd2spdy_http.h @@ -38,11 +38,17 @@ http_cb_request (void *cls, void **ptr); -void * http_log_cb(void * cls, const char * uri); +void * http_cb_log(void * cls, const char * uri); void http_create_response(struct Proxy* proxy, char **nv); +void +http_cb_request_completed (void *cls, + struct MHD_Connection *connection, + void **con_cls, + enum MHD_RequestTerminationCode toe); + #endif diff --git a/src/examples/mhd2spdy_spdy.c b/src/examples/mhd2spdy_spdy.c @@ -334,7 +334,7 @@ spdy_cb_on_ctrl_recv(spdylay_session *session, break; case SPDYLAY_RST_STREAM: PRINT_INFO2("received reset stream for %s", proxy->url); - proxy->error = true; + proxy->spdy_error = true; break; case SPDYLAY_HEADERS: PRINT_INFO2("received headers for %s", proxy->url); @@ -398,7 +398,13 @@ spdy_cb_on_data_chunk_recv(spdylay_session *session, struct Proxy *proxy; proxy = spdylay_session_get_stream_user_data(session, stream_id); - + + if(NULL == proxy) + { + PRINT_INFO("proxy in spdy_cb_on_data_chunk_recv is NULL)"); + return; + } + if(!copy_buffer(data, len, &proxy->http_body, &proxy->http_body_size)) { //TODO handle it better? @@ -1076,9 +1082,9 @@ spdy_run_select(fd_set * read_fd_set, else { PRINT_INFO("not called"); - PRINT_INFO2("connection->want_io %i",connections[i]->want_io); - PRINT_INFO2("read %i",spdylay_session_want_read(connections[i]->session)); - PRINT_INFO2("write %i",spdylay_session_want_write(connections[i]->session)); + //PRINT_INFO2("connection->want_io %i",connections[i]->want_io); + //PRINT_INFO2("read %i",spdylay_session_want_read(connections[i]->session)); + //PRINT_INFO2("write %i",spdylay_session_want_write(connections[i]->session)); //raise(SIGINT); } } diff --git a/src/examples/mhd2spdy_structures.h b/src/examples/mhd2spdy_structures.h @@ -120,7 +120,8 @@ struct Proxy int id; int32_t stream_id; bool done; - bool error; + bool http_error; + bool spdy_error; bool http_active; bool spdy_active; bool receiving_done;