From 22e0954068ff70395f77c00e36635efcd35e2e31 Mon Sep 17 00:00:00 2001 From: Andrey Uzunov Date: Sat, 20 Jul 2013 17:03:17 +0000 Subject: [PATCH] mhd2spdy: changes, still importing --- src/examples/mhd2spdy.c | 18 +++++++++++------- src/examples/mhd2spdy_http.c | 7 +++++-- src/examples/mhd2spdy_spdy.c | 22 +++++++++++++++++++++- src/examples/mhd2spdy_structures.c | 2 +- src/examples/mhd2spdy_structures.h | 2 ++ 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/examples/mhd2spdy.c b/src/examples/mhd2spdy.c index 507641c2..10d0afd4 100644 --- a/src/examples/mhd2spdy.c +++ b/src/examples/mhd2spdy.c @@ -41,6 +41,7 @@ static int run = 1; static void catch_signal(int signal) { + (void)signal; //spdy_close = 1; run = 0; } @@ -122,7 +123,7 @@ run_everything () if(NULL == glob_opt.spdy_connection && glob_opt.only_proxy) PRINT_INFO("cannot connect to the proxy"); } - + //PRINT_INFO("while1"); FD_ZERO(&rs); FD_ZERO(&ws); @@ -166,7 +167,7 @@ else{*/ connections, MAX_SPDY_CONNECTIONS, &spdy_npollfds); if(maxfd_s > maxfd) maxfd = maxfd_s; - PRINT_INFO2("MHD timeout %i %i", timeout.tv_sec, timeout.tv_usec); + PRINT_INFO2("MHD timeout %lld %lld", (unsigned long long)timeout.tv_sec, (unsigned long long)timeout.tv_usec); //TODO //timeout.tv_sec = 0; //timeout.tv_usec = 0; @@ -174,9 +175,10 @@ else{*/ glob_opt.spdy_data_received = false; ret = select(maxfd+1, &rs, &ws, &es, &timeout); - PRINT_INFO2("timeout now %i %i", timeout.tv_sec, timeout.tv_usec); + PRINT_INFO2("timeout now %lld %lld", (unsigned long long)timeout.tv_sec, (unsigned long long)timeout.tv_usec); - switch(ret) { + switch(ret) + { case -1: PRINT_INFO2("select error: %i", errno); break; @@ -184,12 +186,14 @@ else{*/ break; default: PRINT_INFO("run"); - MHD_run_from_select(daemon,&rs, &ws, &es); + //MHD_run_from_select(daemon,&rs, &ws, &es); //not closing FDs + MHD_run(daemon); spdy_run_select(&rs, &ws, &es, connections, spdy_npollfds); if(glob_opt.spdy_data_received) { PRINT_INFO("MHD run again"); - MHD_run_from_select(daemon,&rs, &ws, &es); + //MHD_run_from_select(daemon,&rs, &ws, &es); //not closing FDs + MHD_run(daemon); } break; } @@ -215,7 +219,7 @@ else{*/ }*/ } while(run); - + //TODO exit from loop and clean MHD_stop_daemon (daemon); diff --git a/src/examples/mhd2spdy_http.c b/src/examples/mhd2spdy_http.c index 5f788524..2e9df268 100644 --- a/src/examples/mhd2spdy_http.c +++ b/src/examples/mhd2spdy_http.c @@ -31,6 +31,7 @@ void * http_log_cb(void * cls, const char * uri) PRINT_INFO2("log uri '%s'\n", uri); + //TODO free if(NULL == (http_uri = au_malloc(sizeof(struct HTTP_URI )))) DIE("no memory"); //memset(http_uri, 0 , sizeof(struct HTTP_URI)); @@ -100,6 +101,9 @@ http_response_callback (void *cls, PRINT_INFO2("http_response_callback for %s", proxy->url); + if(proxy->error) + return MHD_CONTENT_READER_END_WITH_ERROR; + if(0 == proxy->http_body_size &&( proxy->done || !proxy->spdy_active)){ PRINT_INFO("sent end of stream"); return MHD_CONTENT_READER_END_OF_STREAM; @@ -183,7 +187,6 @@ http_response_done_callback(void *cls) */ //SPDY_destroy_request(request); //SPDY_destroy_response(response); - MHD_destroy_response (proxy->http_response); //if(!strcmp("/close",proxy->path)) run = 0; //free(proxy->path); if(proxy->spdy_active) @@ -349,7 +352,6 @@ http_cb_request (void *cls, if(MHD_NO == MHD_add_response_header (proxy->http_response, "Keep-Alive", "timeout=5, max=100")) PRINT_INFO("SPDY_name_value_add failed: "); - /* const union MHD_ConnectionInfo *info; info = MHD_get_connection_info (connection, @@ -447,4 +449,5 @@ http_create_response(struct Proxy* proxy, char **nv) //MHD_destroy_response (proxy->http_response); //PRINT_INFO2("state after %i", proxy->http_connection->state); //PRINT_INFO2("loop after %i", proxy->http_connection->event_loop_info); + MHD_destroy_response (proxy->http_response); } diff --git a/src/examples/mhd2spdy_spdy.c b/src/examples/mhd2spdy_spdy.c index 93cad507..99b2a3a1 100644 --- a/src/examples/mhd2spdy_spdy.c +++ b/src/examples/mhd2spdy_spdy.c @@ -236,6 +236,9 @@ void spdy_cb_on_ctrl_recv(spdylay_session *session, //name = "SYN_REPLY"; stream_id = frame->syn_reply.stream_id; break; + case SPDYLAY_RST_STREAM: + stream_id = frame->rst_stream.stream_id; + break; case SPDYLAY_HEADERS: nv = frame->headers.nv; //name = "HEADERS"; @@ -247,9 +250,26 @@ void spdy_cb_on_ctrl_recv(spdylay_session *session, } proxy = spdylay_session_get_stream_user_data(session, stream_id); - PRINT_INFO2("received headers for %s", proxy->url); + if(NULL == proxy) + DIE("no proxy obj"); + switch(type) { + case SPDYLAY_SYN_REPLY: + PRINT_INFO2("received headers for %s", proxy->url); http_create_response(proxy, nv); + break; + case SPDYLAY_RST_STREAM: + PRINT_INFO2("received reset stream for %s", proxy->url); + proxy->error = true; + break; + case SPDYLAY_HEADERS: + PRINT_INFO2("received headers for %s", proxy->url); + http_create_response(proxy, nv); + break; + default: + return; + break; + } glob_opt.spdy_data_received = true; } diff --git a/src/examples/mhd2spdy_structures.c b/src/examples/mhd2spdy_structures.c index a3486e3a..f7d54c4c 100644 --- a/src/examples/mhd2spdy_structures.c +++ b/src/examples/mhd2spdy_structures.c @@ -127,7 +127,7 @@ parse_uri(regex_t * preg, char * full_uri, struct URI ** uri) void free_proxy(struct Proxy *proxy) { - //PRINT_INFO("free proxy called"); + PRINT_INFO2("free proxy called for '%s'", proxy->url); free(proxy->http_body); free_uri(proxy->uri); free(proxy->url); diff --git a/src/examples/mhd2spdy_structures.h b/src/examples/mhd2spdy_structures.h index 175dc62e..0900964f 100644 --- a/src/examples/mhd2spdy_structures.h +++ b/src/examples/mhd2spdy_structures.h @@ -113,10 +113,12 @@ struct Proxy int status; int id; bool done; + bool error; bool http_active; bool spdy_active; }; + struct HTTP_URI { char * uri;