diff options
author | Andrey Uzunov <andrey.uzunov@gmail.com> | 2013-07-20 17:03:17 +0000 |
---|---|---|
committer | Andrey Uzunov <andrey.uzunov@gmail.com> | 2013-07-20 17:03:17 +0000 |
commit | 22e0954068ff70395f77c00e36635efcd35e2e31 (patch) | |
tree | ce9efb6670be8c4c6470f9c86431265da99c3ba8 | |
parent | 38381f24c4065b7b55d0f6d1e095df53af83f407 (diff) | |
download | libmicrohttpd-22e0954068ff70395f77c00e36635efcd35e2e31.tar.gz libmicrohttpd-22e0954068ff70395f77c00e36635efcd35e2e31.zip |
mhd2spdy: changes, still importing
-rw-r--r-- | src/examples/mhd2spdy.c | 18 | ||||
-rw-r--r-- | src/examples/mhd2spdy_http.c | 7 | ||||
-rw-r--r-- | src/examples/mhd2spdy_spdy.c | 22 | ||||
-rw-r--r-- | src/examples/mhd2spdy_structures.c | 2 | ||||
-rw-r--r-- | 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; | |||
41 | 41 | ||
42 | static void catch_signal(int signal) | 42 | static void catch_signal(int signal) |
43 | { | 43 | { |
44 | (void)signal; | ||
44 | //spdy_close = 1; | 45 | //spdy_close = 1; |
45 | run = 0; | 46 | run = 0; |
46 | } | 47 | } |
@@ -122,7 +123,7 @@ run_everything () | |||
122 | if(NULL == glob_opt.spdy_connection && glob_opt.only_proxy) | 123 | if(NULL == glob_opt.spdy_connection && glob_opt.only_proxy) |
123 | PRINT_INFO("cannot connect to the proxy"); | 124 | PRINT_INFO("cannot connect to the proxy"); |
124 | } | 125 | } |
125 | 126 | ||
126 | //PRINT_INFO("while1"); | 127 | //PRINT_INFO("while1"); |
127 | FD_ZERO(&rs); | 128 | FD_ZERO(&rs); |
128 | FD_ZERO(&ws); | 129 | FD_ZERO(&ws); |
@@ -166,7 +167,7 @@ else{*/ | |||
166 | connections, MAX_SPDY_CONNECTIONS, &spdy_npollfds); | 167 | connections, MAX_SPDY_CONNECTIONS, &spdy_npollfds); |
167 | if(maxfd_s > maxfd) maxfd = maxfd_s; | 168 | if(maxfd_s > maxfd) maxfd = maxfd_s; |
168 | 169 | ||
169 | PRINT_INFO2("MHD timeout %i %i", timeout.tv_sec, timeout.tv_usec); | 170 | PRINT_INFO2("MHD timeout %lld %lld", (unsigned long long)timeout.tv_sec, (unsigned long long)timeout.tv_usec); |
170 | //TODO | 171 | //TODO |
171 | //timeout.tv_sec = 0; | 172 | //timeout.tv_sec = 0; |
172 | //timeout.tv_usec = 0; | 173 | //timeout.tv_usec = 0; |
@@ -174,9 +175,10 @@ else{*/ | |||
174 | glob_opt.spdy_data_received = false; | 175 | glob_opt.spdy_data_received = false; |
175 | 176 | ||
176 | ret = select(maxfd+1, &rs, &ws, &es, &timeout); | 177 | ret = select(maxfd+1, &rs, &ws, &es, &timeout); |
177 | PRINT_INFO2("timeout now %i %i", timeout.tv_sec, timeout.tv_usec); | 178 | PRINT_INFO2("timeout now %lld %lld", (unsigned long long)timeout.tv_sec, (unsigned long long)timeout.tv_usec); |
178 | 179 | ||
179 | switch(ret) { | 180 | switch(ret) |
181 | { | ||
180 | case -1: | 182 | case -1: |
181 | PRINT_INFO2("select error: %i", errno); | 183 | PRINT_INFO2("select error: %i", errno); |
182 | break; | 184 | break; |
@@ -184,12 +186,14 @@ else{*/ | |||
184 | break; | 186 | break; |
185 | default: | 187 | default: |
186 | PRINT_INFO("run"); | 188 | PRINT_INFO("run"); |
187 | MHD_run_from_select(daemon,&rs, &ws, &es); | 189 | //MHD_run_from_select(daemon,&rs, &ws, &es); //not closing FDs |
190 | MHD_run(daemon); | ||
188 | spdy_run_select(&rs, &ws, &es, connections, spdy_npollfds); | 191 | spdy_run_select(&rs, &ws, &es, connections, spdy_npollfds); |
189 | if(glob_opt.spdy_data_received) | 192 | if(glob_opt.spdy_data_received) |
190 | { | 193 | { |
191 | PRINT_INFO("MHD run again"); | 194 | PRINT_INFO("MHD run again"); |
192 | MHD_run_from_select(daemon,&rs, &ws, &es); | 195 | //MHD_run_from_select(daemon,&rs, &ws, &es); //not closing FDs |
196 | MHD_run(daemon); | ||
193 | } | 197 | } |
194 | break; | 198 | break; |
195 | } | 199 | } |
@@ -215,7 +219,7 @@ else{*/ | |||
215 | }*/ | 219 | }*/ |
216 | } | 220 | } |
217 | while(run); | 221 | while(run); |
218 | 222 | ||
219 | //TODO exit from loop and clean | 223 | //TODO exit from loop and clean |
220 | 224 | ||
221 | MHD_stop_daemon (daemon); | 225 | 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) | |||
31 | 31 | ||
32 | PRINT_INFO2("log uri '%s'\n", uri); | 32 | PRINT_INFO2("log uri '%s'\n", uri); |
33 | 33 | ||
34 | //TODO free | ||
34 | if(NULL == (http_uri = au_malloc(sizeof(struct HTTP_URI )))) | 35 | if(NULL == (http_uri = au_malloc(sizeof(struct HTTP_URI )))) |
35 | DIE("no memory"); | 36 | DIE("no memory"); |
36 | //memset(http_uri, 0 , sizeof(struct HTTP_URI)); | 37 | //memset(http_uri, 0 , sizeof(struct HTTP_URI)); |
@@ -100,6 +101,9 @@ http_response_callback (void *cls, | |||
100 | 101 | ||
101 | PRINT_INFO2("http_response_callback for %s", proxy->url); | 102 | PRINT_INFO2("http_response_callback for %s", proxy->url); |
102 | 103 | ||
104 | if(proxy->error) | ||
105 | return MHD_CONTENT_READER_END_WITH_ERROR; | ||
106 | |||
103 | if(0 == proxy->http_body_size &&( proxy->done || !proxy->spdy_active)){ | 107 | if(0 == proxy->http_body_size &&( proxy->done || !proxy->spdy_active)){ |
104 | PRINT_INFO("sent end of stream"); | 108 | PRINT_INFO("sent end of stream"); |
105 | return MHD_CONTENT_READER_END_OF_STREAM; | 109 | return MHD_CONTENT_READER_END_OF_STREAM; |
@@ -183,7 +187,6 @@ http_response_done_callback(void *cls) | |||
183 | */ | 187 | */ |
184 | //SPDY_destroy_request(request); | 188 | //SPDY_destroy_request(request); |
185 | //SPDY_destroy_response(response); | 189 | //SPDY_destroy_response(response); |
186 | MHD_destroy_response (proxy->http_response); | ||
187 | //if(!strcmp("/close",proxy->path)) run = 0; | 190 | //if(!strcmp("/close",proxy->path)) run = 0; |
188 | //free(proxy->path); | 191 | //free(proxy->path); |
189 | if(proxy->spdy_active) | 192 | if(proxy->spdy_active) |
@@ -349,7 +352,6 @@ http_cb_request (void *cls, | |||
349 | if(MHD_NO == MHD_add_response_header (proxy->http_response, | 352 | if(MHD_NO == MHD_add_response_header (proxy->http_response, |
350 | "Keep-Alive", "timeout=5, max=100")) | 353 | "Keep-Alive", "timeout=5, max=100")) |
351 | PRINT_INFO("SPDY_name_value_add failed: "); | 354 | PRINT_INFO("SPDY_name_value_add failed: "); |
352 | |||
353 | /* | 355 | /* |
354 | const union MHD_ConnectionInfo *info; | 356 | const union MHD_ConnectionInfo *info; |
355 | info = MHD_get_connection_info (connection, | 357 | info = MHD_get_connection_info (connection, |
@@ -447,4 +449,5 @@ http_create_response(struct Proxy* proxy, char **nv) | |||
447 | //MHD_destroy_response (proxy->http_response); | 449 | //MHD_destroy_response (proxy->http_response); |
448 | //PRINT_INFO2("state after %i", proxy->http_connection->state); | 450 | //PRINT_INFO2("state after %i", proxy->http_connection->state); |
449 | //PRINT_INFO2("loop after %i", proxy->http_connection->event_loop_info); | 451 | //PRINT_INFO2("loop after %i", proxy->http_connection->event_loop_info); |
452 | MHD_destroy_response (proxy->http_response); | ||
450 | } | 453 | } |
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, | |||
236 | //name = "SYN_REPLY"; | 236 | //name = "SYN_REPLY"; |
237 | stream_id = frame->syn_reply.stream_id; | 237 | stream_id = frame->syn_reply.stream_id; |
238 | break; | 238 | break; |
239 | case SPDYLAY_RST_STREAM: | ||
240 | stream_id = frame->rst_stream.stream_id; | ||
241 | break; | ||
239 | case SPDYLAY_HEADERS: | 242 | case SPDYLAY_HEADERS: |
240 | nv = frame->headers.nv; | 243 | nv = frame->headers.nv; |
241 | //name = "HEADERS"; | 244 | //name = "HEADERS"; |
@@ -247,9 +250,26 @@ void spdy_cb_on_ctrl_recv(spdylay_session *session, | |||
247 | } | 250 | } |
248 | 251 | ||
249 | proxy = spdylay_session_get_stream_user_data(session, stream_id); | 252 | proxy = spdylay_session_get_stream_user_data(session, stream_id); |
250 | PRINT_INFO2("received headers for %s", proxy->url); | 253 | if(NULL == proxy) |
254 | DIE("no proxy obj"); | ||
251 | 255 | ||
256 | switch(type) { | ||
257 | case SPDYLAY_SYN_REPLY: | ||
258 | PRINT_INFO2("received headers for %s", proxy->url); | ||
252 | http_create_response(proxy, nv); | 259 | http_create_response(proxy, nv); |
260 | break; | ||
261 | case SPDYLAY_RST_STREAM: | ||
262 | PRINT_INFO2("received reset stream for %s", proxy->url); | ||
263 | proxy->error = true; | ||
264 | break; | ||
265 | case SPDYLAY_HEADERS: | ||
266 | PRINT_INFO2("received headers for %s", proxy->url); | ||
267 | http_create_response(proxy, nv); | ||
268 | break; | ||
269 | default: | ||
270 | return; | ||
271 | break; | ||
272 | } | ||
253 | glob_opt.spdy_data_received = true; | 273 | glob_opt.spdy_data_received = true; |
254 | } | 274 | } |
255 | 275 | ||
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) | |||
127 | void | 127 | void |
128 | free_proxy(struct Proxy *proxy) | 128 | free_proxy(struct Proxy *proxy) |
129 | { | 129 | { |
130 | //PRINT_INFO("free proxy called"); | 130 | PRINT_INFO2("free proxy called for '%s'", proxy->url); |
131 | free(proxy->http_body); | 131 | free(proxy->http_body); |
132 | free_uri(proxy->uri); | 132 | free_uri(proxy->uri); |
133 | free(proxy->url); | 133 | 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 | |||
113 | int status; | 113 | int status; |
114 | int id; | 114 | int id; |
115 | bool done; | 115 | bool done; |
116 | bool error; | ||
116 | bool http_active; | 117 | bool http_active; |
117 | bool spdy_active; | 118 | bool spdy_active; |
118 | }; | 119 | }; |
119 | 120 | ||
121 | |||
120 | struct HTTP_URI | 122 | struct HTTP_URI |
121 | { | 123 | { |
122 | char * uri; | 124 | char * uri; |