diff options
author | Andrey Uzunov <andrey.uzunov@gmail.com> | 2013-09-03 10:48:18 +0000 |
---|---|---|
committer | Andrey Uzunov <andrey.uzunov@gmail.com> | 2013-09-03 10:48:18 +0000 |
commit | b49eb1361d97478f5ae80f6b00e781a38aaee301 (patch) | |
tree | 481044c8eb8de4e5927060e2b0c62d4576237649 | |
parent | d74282806eb98340cea23a4b8db8da3c16f5e3c6 (diff) | |
download | libmicrohttpd-b49eb1361d97478f5ae80f6b00e781a38aaee301.tar.gz libmicrohttpd-b49eb1361d97478f5ae80f6b00e781a38aaee301.zip |
mhd2spdy: segfaults on cleaning up proxy structs fixed
-rw-r--r-- | src/examples/mhd2spdy.c | 5 | ||||
-rw-r--r-- | src/examples/mhd2spdy_http.c | 104 | ||||
-rw-r--r-- | src/examples/mhd2spdy_spdy.c | 77 |
3 files changed, 107 insertions, 79 deletions
diff --git a/src/examples/mhd2spdy.c b/src/examples/mhd2spdy.c index e44d3269..3d5c2e17 100644 --- a/src/examples/mhd2spdy.c +++ b/src/examples/mhd2spdy.c | |||
@@ -23,6 +23,7 @@ | |||
23 | * TODOs: | 23 | * TODOs: |
24 | * - non blocking SSL connect | 24 | * - non blocking SSL connect |
25 | * - check certificate | 25 | * - check certificate |
26 | * - on closing spdy session, close sockets for all requests | ||
26 | * @author Andrey Uzunov | 27 | * @author Andrey Uzunov |
27 | */ | 28 | */ |
28 | 29 | ||
@@ -87,7 +88,7 @@ run_everything () | |||
87 | 88 | ||
88 | glob_opt.streams_opened = 0; | 89 | glob_opt.streams_opened = 0; |
89 | glob_opt.responses_pending = 0; | 90 | glob_opt.responses_pending = 0; |
90 | glob_opt.global_memory = 0; | 91 | //glob_opt.global_memory = 0; |
91 | 92 | ||
92 | srand(time(NULL)); | 93 | srand(time(NULL)); |
93 | 94 | ||
@@ -217,7 +218,7 @@ run_everything () | |||
217 | EVP_cleanup(); | 218 | EVP_cleanup(); |
218 | 219 | ||
219 | PRINT_INFO2("spdy streams: %i; http requests: %i", glob_opt.streams_opened, glob_opt.responses_pending); | 220 | PRINT_INFO2("spdy streams: %i; http requests: %i", glob_opt.streams_opened, glob_opt.responses_pending); |
220 | PRINT_INFO2("memory allocated %zu bytes", glob_opt.global_memory); | 221 | //PRINT_INFO2("memory allocated %zu bytes", glob_opt.global_memory); |
221 | 222 | ||
222 | print_stat(); | 223 | print_stat(); |
223 | 224 | ||
diff --git a/src/examples/mhd2spdy_http.c b/src/examples/mhd2spdy_http.c index cf9f6c52..063b6d58 100644 --- a/src/examples/mhd2spdy_http.c +++ b/src/examples/mhd2spdy_http.c | |||
@@ -38,7 +38,7 @@ const char * uri) | |||
38 | 38 | ||
39 | //TODO not freed once in a while | 39 | //TODO not freed once in a while |
40 | if(NULL == (http_uri = au_malloc(sizeof(struct HTTP_URI )))) | 40 | if(NULL == (http_uri = au_malloc(sizeof(struct HTTP_URI )))) |
41 | DIE("no memory"); | 41 | return NULL; |
42 | http_uri->uri = strdup(uri); | 42 | http_uri->uri = strdup(uri); |
43 | return http_uri; | 43 | return http_uri; |
44 | } | 44 | } |
@@ -94,7 +94,8 @@ http_cb_response (void *cls, | |||
94 | if(proxy->spdy_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)) |
98 | { | ||
98 | PRINT_INFO("sent end of stream"); | 99 | PRINT_INFO("sent end of stream"); |
99 | return MHD_CONTENT_READER_END_OF_STREAM; | 100 | return MHD_CONTENT_READER_END_OF_STREAM; |
100 | } | 101 | } |
@@ -124,7 +125,7 @@ http_cb_response (void *cls, | |||
124 | if(NULL == (newbody = au_malloc(proxy->http_body_size - max))) | 125 | if(NULL == (newbody = au_malloc(proxy->http_body_size - max))) |
125 | { | 126 | { |
126 | PRINT_INFO("no memory"); | 127 | PRINT_INFO("no memory"); |
127 | return -2; | 128 | return MHD_CONTENT_READER_END_WITH_ERROR; |
128 | } | 129 | } |
129 | memcpy(newbody, proxy->http_body + max, proxy->http_body_size - max); | 130 | memcpy(newbody, proxy->http_body + max, proxy->http_body_size - max); |
130 | } | 131 | } |
@@ -147,12 +148,6 @@ http_cb_response (void *cls, | |||
147 | static void | 148 | static void |
148 | http_cb_response_done(void *cls) | 149 | http_cb_response_done(void *cls) |
149 | { | 150 | { |
150 | |||
151 | //TODO | ||
152 | /*struct Proxy *proxy = (struct Proxy *)cls; | ||
153 | |||
154 | PRINT_INFO2("http_cb_response_done for %s", proxy->url); | ||
155 | */ | ||
156 | 151 | ||
157 | } | 152 | } |
158 | 153 | ||
@@ -175,15 +170,16 @@ http_cb_request (void *cls, | |||
175 | struct Proxy *proxy; | 170 | struct Proxy *proxy; |
176 | struct SPDY_Headers spdy_headers; | 171 | struct SPDY_Headers spdy_headers; |
177 | bool with_body = false; | 172 | bool with_body = false; |
178 | 173 | struct HTTP_URI *http_uri; | |
179 | //PRINT_INFO2("request cb %i; %s", *ptr,url); | ||
180 | 174 | ||
181 | if (NULL == *ptr) | 175 | if (NULL == ptr || NULL == *ptr) |
182 | DIE("ptr is null"); | 176 | return MHD_NO; |
183 | struct HTTP_URI *http_uri = (struct HTTP_URI *)*ptr; | 177 | |
178 | http_uri = (struct HTTP_URI *)*ptr; | ||
184 | 179 | ||
185 | if(NULL == http_uri->proxy) | 180 | if(NULL == http_uri->proxy) |
186 | { | 181 | { |
182 | //first call for this request | ||
187 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET) && 0 != strcmp (method, MHD_HTTP_METHOD_POST)) | 183 | if (0 != strcmp (method, MHD_HTTP_METHOD_GET) && 0 != strcmp (method, MHD_HTTP_METHOD_POST)) |
188 | { | 184 | { |
189 | free(http_uri->uri); | 185 | free(http_uri->uri); |
@@ -207,12 +203,15 @@ http_cb_request (void *cls, | |||
207 | } | 203 | } |
208 | 204 | ||
209 | proxy = http_uri->proxy; | 205 | proxy = http_uri->proxy; |
206 | |||
207 | if(proxy->spdy_error || proxy->http_error) | ||
208 | return MHD_NO; // handled at different place TODO? leaks? | ||
210 | 209 | ||
211 | if(proxy->spdy_active) | 210 | if(proxy->spdy_active) |
212 | { | 211 | { |
213 | if(0 == strcmp (method, MHD_HTTP_METHOD_POST)) | 212 | if(0 == strcmp (method, MHD_HTTP_METHOD_POST)) |
214 | { | 213 | { |
215 | PRINT_INFO("POST processing"); | 214 | PRINT_INFO("POST processing"); |
216 | 215 | ||
217 | int rc= spdylay_session_resume_data(proxy->spdy_connection->session, proxy->stream_id); | 216 | int rc= spdylay_session_resume_data(proxy->spdy_connection->session, proxy->stream_id); |
218 | PRINT_INFO2("rc is %i stream is %i", rc, proxy->stream_id); | 217 | PRINT_INFO2("rc is %i stream is %i", rc, proxy->stream_id); |
@@ -231,24 +230,8 @@ http_cb_request (void *cls, | |||
231 | PRINT_INFO("not enough memory (malloc/realloc returned NULL)"); | 230 | PRINT_INFO("not enough memory (malloc/realloc returned NULL)"); |
232 | return MHD_NO; | 231 | return MHD_NO; |
233 | } | 232 | } |
234 | /* | ||
235 | if(NULL == proxy->received_body) | ||
236 | proxy->received_body = malloc(*upload_data_size); | ||
237 | else | ||
238 | proxy->received_body = realloc(proxy->received_body, proxy->received_body_size + *upload_data_size); | ||
239 | if(NULL == proxy->received_body) | ||
240 | { | ||
241 | //TODO handle it better? | ||
242 | PRINT_INFO("not enough memory (realloc returned NULL)"); | ||
243 | return MHD_NO; | ||
244 | } | ||
245 | |||
246 | memcpy(proxy->received_body + proxy->received_body_size, upload_data, *upload_data_size); | ||
247 | proxy->received_body_size += *upload_data_size; | ||
248 | */ | ||
249 | *upload_data_size = 0; | ||
250 | 233 | ||
251 | //raise(SIGINT); | 234 | *upload_data_size = 0; |
252 | 235 | ||
253 | return MHD_YES; | 236 | return MHD_YES; |
254 | } | 237 | } |
@@ -257,12 +240,15 @@ http_cb_request (void *cls, | |||
257 | PRINT_INFO("unnecessary call to http_cb_request"); | 240 | PRINT_INFO("unnecessary call to http_cb_request"); |
258 | return MHD_YES; | 241 | return MHD_YES; |
259 | } | 242 | } |
243 | |||
244 | //second call for this request | ||
260 | 245 | ||
261 | PRINT_INFO2("received request for '%s %s %s'", method, http_uri->uri, version); | 246 | PRINT_INFO2("received request for '%s %s %s'", method, http_uri->uri, version); |
262 | 247 | ||
263 | proxy->url = http_uri->uri; | 248 | proxy->url = http_uri->uri; |
264 | 249 | ||
265 | with_body = 0 == strcmp (method, MHD_HTTP_METHOD_POST) && 0 != strcmp ("0", | 250 | with_body = 0 == strcmp (method, MHD_HTTP_METHOD_POST) |
251 | && 0 != strcmp ("0", | ||
266 | MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_LENGTH)); | 252 | MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_LENGTH)); |
267 | 253 | ||
268 | PRINT_INFO2("body will be sent %i", with_body); | 254 | PRINT_INFO2("body will be sent %i", with_body); |
@@ -271,7 +257,6 @@ http_cb_request (void *cls, | |||
271 | if(ret != 0) | 257 | if(ret != 0) |
272 | DIE("parse_uri failed"); | 258 | DIE("parse_uri failed"); |
273 | proxy->http_uri = http_uri; | 259 | proxy->http_uri = http_uri; |
274 | proxy->spdy_active = true; | ||
275 | 260 | ||
276 | spdy_headers.num = MHD_get_connection_values (connection, | 261 | spdy_headers.num = MHD_get_connection_values (connection, |
277 | MHD_HEADER_KIND, | 262 | MHD_HEADER_KIND, |
@@ -298,7 +283,7 @@ http_cb_request (void *cls, | |||
298 | if(0 != spdy_request(spdy_headers.nv, proxy, with_body)) | 283 | if(0 != spdy_request(spdy_headers.nv, proxy, with_body)) |
299 | { | 284 | { |
300 | free(spdy_headers.nv); | 285 | free(spdy_headers.nv); |
301 | free_proxy(proxy); | 286 | //free_proxy(proxy); |
302 | 287 | ||
303 | return MHD_NO; | 288 | return MHD_NO; |
304 | } | 289 | } |
@@ -310,7 +295,7 @@ http_cb_request (void *cls, | |||
310 | proxy, | 295 | proxy, |
311 | &http_cb_response_done); | 296 | &http_cb_response_done); |
312 | 297 | ||
313 | if (proxy->http_response == NULL) | 298 | if (NULL == proxy->http_response) |
314 | DIE("no response"); | 299 | DIE("no response"); |
315 | 300 | ||
316 | if(MHD_NO == MHD_add_response_header (proxy->http_response, | 301 | if(MHD_NO == MHD_add_response_header (proxy->http_response, |
@@ -323,6 +308,8 @@ http_cb_request (void *cls, | |||
323 | "Keep-Alive", "timeout=5, max=100")) | 308 | "Keep-Alive", "timeout=5, max=100")) |
324 | PRINT_INFO("SPDY_name_value_add failed: "); | 309 | PRINT_INFO("SPDY_name_value_add failed: "); |
325 | 310 | ||
311 | proxy->spdy_active = true; | ||
312 | |||
326 | return MHD_YES; | 313 | return MHD_YES; |
327 | } | 314 | } |
328 | 315 | ||
@@ -333,6 +320,9 @@ http_create_response(struct Proxy* proxy, | |||
333 | { | 320 | { |
334 | size_t i; | 321 | size_t i; |
335 | 322 | ||
323 | if(!proxy->http_active) | ||
324 | return; | ||
325 | |||
336 | for(i = 0; nv[i]; i += 2) { | 326 | for(i = 0; nv[i]; i += 2) { |
337 | if(0 == strcmp(":status", nv[i])) | 327 | if(0 == strcmp(":status", nv[i])) |
338 | { | 328 | { |
@@ -363,10 +353,13 @@ http_create_response(struct Proxy* proxy, | |||
363 | 353 | ||
364 | if(MHD_NO == MHD_queue_response (proxy->http_connection, proxy->status, proxy->http_response)){ | 354 | if(MHD_NO == MHD_queue_response (proxy->http_connection, proxy->status, proxy->http_response)){ |
365 | PRINT_INFO("No queue"); | 355 | PRINT_INFO("No queue"); |
366 | abort(); | 356 | //TODO |
357 | //abort(); | ||
358 | proxy->http_error = true; | ||
367 | } | 359 | } |
368 | 360 | ||
369 | MHD_destroy_response (proxy->http_response); | 361 | MHD_destroy_response (proxy->http_response); |
362 | proxy->http_response = NULL; | ||
370 | } | 363 | } |
371 | 364 | ||
372 | void | 365 | void |
@@ -375,11 +368,22 @@ http_cb_request_completed (void *cls, | |||
375 | void **con_cls, | 368 | void **con_cls, |
376 | enum MHD_RequestTerminationCode toe) | 369 | enum MHD_RequestTerminationCode toe) |
377 | { | 370 | { |
378 | struct HTTP_URI *http_uri = (struct HTTP_URI *)*con_cls; | 371 | struct HTTP_URI *http_uri; |
379 | if(NULL == http_uri) return; | 372 | struct Proxy *proxy; |
380 | struct Proxy *proxy = (struct Proxy *)http_uri->proxy; | 373 | |
374 | http_uri = (struct HTTP_URI *)*con_cls; | ||
375 | if(NULL == http_uri) | ||
376 | return; | ||
377 | proxy = (struct Proxy *)http_uri->proxy; | ||
378 | assert(NULL != proxy); | ||
381 | 379 | ||
382 | PRINT_INFO2("http_cb_request_completed %i for %s",toe, http_uri->uri); | 380 | PRINT_INFO2("http_cb_request_completed %i for %s; id %i",toe, http_uri->uri, proxy->id); |
381 | |||
382 | if(NULL != proxy->http_response) | ||
383 | { | ||
384 | MHD_destroy_response (proxy->http_response); | ||
385 | proxy->http_response = NULL; | ||
386 | } | ||
383 | 387 | ||
384 | if(proxy->spdy_active) | 388 | if(proxy->spdy_active) |
385 | { | 389 | { |
@@ -387,14 +391,20 @@ http_cb_request_completed (void *cls, | |||
387 | if(MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) | 391 | if(MHD_REQUEST_TERMINATED_COMPLETED_OK != toe) |
388 | { | 392 | { |
389 | proxy->http_error = true; | 393 | proxy->http_error = true; |
390 | assert(proxy->stream_id > 0); | 394 | if(proxy->stream_id > 0 && NULL != proxy->spdy_connection->session) |
391 | //send RST_STREAM_STATUS_CANCEL | 395 | { |
392 | PRINT_INFO("send rst_stream" ); | 396 | //send RST_STREAM_STATUS_CANCEL |
393 | spdylay_submit_rst_stream(proxy->spdy_connection->session, proxy->stream_id, 5); | 397 | PRINT_INFO2("send rst_stream %i",proxy->spdy_active ); |
398 | spdylay_submit_rst_stream(proxy->spdy_connection->session, proxy->stream_id, 5); | ||
399 | } | ||
394 | } | 400 | } |
395 | } | 401 | } |
396 | else | 402 | else |
397 | free_proxy(proxy); | 403 | { |
404 | PRINT_INFO2("proxy free http id %i ", proxy->id); | ||
405 | //DLL_remove(proxy->spdy_connection->proxies_head, proxy->spdy_connection->proxies_tail, proxy); | ||
406 | //free_proxy(proxy); | ||
407 | } | ||
398 | 408 | ||
399 | --glob_opt.responses_pending; | 409 | --glob_opt.responses_pending; |
400 | } | 410 | } |
diff --git a/src/examples/mhd2spdy_spdy.c b/src/examples/mhd2spdy_spdy.c index 2bc87976..41c45317 100644 --- a/src/examples/mhd2spdy_spdy.c +++ b/src/examples/mhd2spdy_spdy.c | |||
@@ -370,14 +370,19 @@ spdy_cb_on_stream_close(spdylay_session *session, | |||
370 | 370 | ||
371 | --glob_opt.streams_opened; | 371 | --glob_opt.streams_opened; |
372 | --proxy->spdy_connection->streams_opened; | 372 | --proxy->spdy_connection->streams_opened; |
373 | PRINT_INFO2("closing stream: str opened %i", glob_opt.streams_opened); | 373 | PRINT_INFO2("closing stream: str opened %i; remove proxy %i", glob_opt.streams_opened, proxy->id); |
374 | 374 | ||
375 | DLL_remove(proxy->spdy_connection->proxies_head, proxy->spdy_connection->proxies_tail, proxy); | ||
376 | |||
377 | if(proxy->http_active) | 375 | if(proxy->http_active) |
376 | { | ||
378 | proxy->spdy_active = false; | 377 | proxy->spdy_active = false; |
378 | //DLL_remove(proxy->spdy_connection->proxies_head, proxy->spdy_connection->proxies_tail, proxy); | ||
379 | } | ||
379 | else | 380 | else |
380 | free_proxy(proxy); | 381 | { |
382 | PRINT_INFO2("proxy free close id %i ", proxy->id); | ||
383 | //DLL_remove(proxy->spdy_connection->proxies_head, proxy->spdy_connection->proxies_tail, proxy); | ||
384 | //free_proxy(proxy); | ||
385 | } | ||
381 | } | 386 | } |
382 | 387 | ||
383 | 388 | ||
@@ -615,6 +620,7 @@ spdy_socket_set_tcp_nodelay(int fd) | |||
615 | /* | 620 | /* |
616 | * Update |pollfd| based on the state of |connection|. | 621 | * Update |pollfd| based on the state of |connection|. |
617 | */ | 622 | */ |
623 | /* | ||
618 | void | 624 | void |
619 | spdy_ctl_poll(struct pollfd *pollfd, | 625 | spdy_ctl_poll(struct pollfd *pollfd, |
620 | struct SPDY_Connection *connection) | 626 | struct SPDY_Connection *connection) |
@@ -630,7 +636,7 @@ spdy_ctl_poll(struct pollfd *pollfd, | |||
630 | { | 636 | { |
631 | pollfd->events |= POLLOUT; | 637 | pollfd->events |= POLLOUT; |
632 | } | 638 | } |
633 | } | 639 | }*/ |
634 | 640 | ||
635 | 641 | ||
636 | /* | 642 | /* |
@@ -766,12 +772,26 @@ spdy_connect(const struct URI *uri, | |||
766 | void | 772 | void |
767 | spdy_free_connection(struct SPDY_Connection * connection) | 773 | spdy_free_connection(struct SPDY_Connection * connection) |
768 | { | 774 | { |
775 | struct Proxy *proxy; | ||
776 | |||
769 | if(NULL != connection) | 777 | if(NULL != connection) |
770 | { | 778 | { |
779 | for(proxy = connection->proxies_head; NULL != proxy; proxy=proxy->next) | ||
780 | { | ||
781 | DLL_remove(connection->proxies_head, connection->proxies_tail, proxy); | ||
782 | proxy->spdy_active = false; | ||
783 | proxy->spdy_error = true; | ||
784 | PRINT_INFO2("spdy_free_connection for id %i", proxy->id); | ||
785 | if(!proxy->http_active) | ||
786 | { | ||
787 | //free_proxy(proxy); | ||
788 | } | ||
789 | } | ||
771 | spdylay_session_del(connection->session); | 790 | spdylay_session_del(connection->session); |
772 | SSL_free(connection->ssl); | 791 | SSL_free(connection->ssl); |
773 | free(connection->host); | 792 | free(connection->host); |
774 | free(connection); | 793 | //free(connection); |
794 | connection->session = NULL; | ||
775 | } | 795 | } |
776 | } | 796 | } |
777 | 797 | ||
@@ -835,12 +855,15 @@ spdy_request(const char **nv, | |||
835 | if(ret != 0) { | 855 | if(ret != 0) { |
836 | spdy_diec("spdylay_spdy_submit_request", ret); | 856 | spdy_diec("spdylay_spdy_submit_request", ret); |
837 | } | 857 | } |
858 | PRINT_INFO2("adding proxy %i", proxy->id); | ||
859 | if(NULL != connection->proxies_head) | ||
860 | PRINT_INFO2("before proxy %i", connection->proxies_head->id); | ||
838 | DLL_insert(connection->proxies_head, connection->proxies_tail, proxy); | 861 | DLL_insert(connection->proxies_head, connection->proxies_tail, proxy); |
839 | 862 | ||
840 | return ret; | 863 | return ret; |
841 | } | 864 | } |
842 | 865 | ||
843 | 866 | /* | |
844 | void | 867 | void |
845 | spdy_get_pollfdset(struct pollfd fds[], | 868 | spdy_get_pollfdset(struct pollfd fds[], |
846 | struct SPDY_Connection *connections[], | 869 | struct SPDY_Connection *connections[], |
@@ -864,6 +887,7 @@ spdy_get_pollfdset(struct pollfd fds[], | |||
864 | 887 | ||
865 | for(proxy = glob_opt.spdy_connection->proxies_head; NULL != proxy; proxy=proxy->next) | 888 | for(proxy = glob_opt.spdy_connection->proxies_head; NULL != proxy; proxy=proxy->next) |
866 | { | 889 | { |
890 | abort(); | ||
867 | DLL_remove(glob_opt.spdy_connection->proxies_head, glob_opt.spdy_connection->proxies_tail, proxy); | 891 | DLL_remove(glob_opt.spdy_connection->proxies_head, glob_opt.spdy_connection->proxies_tail, proxy); |
868 | proxy->spdy_active = false; | 892 | proxy->spdy_active = false; |
869 | } | 893 | } |
@@ -893,6 +917,7 @@ spdy_get_pollfdset(struct pollfd fds[], | |||
893 | 917 | ||
894 | for(proxy = connection->proxies_head; NULL != proxy; proxy=proxy->next) | 918 | for(proxy = connection->proxies_head; NULL != proxy; proxy=proxy->next) |
895 | { | 919 | { |
920 | abort(); | ||
896 | DLL_remove(connection->proxies_head, connection->proxies_tail, proxy); | 921 | DLL_remove(connection->proxies_head, connection->proxies_tail, proxy); |
897 | proxy->spdy_active = false; | 922 | proxy->spdy_active = false; |
898 | } | 923 | } |
@@ -910,7 +935,7 @@ spdy_get_pollfdset(struct pollfd fds[], | |||
910 | //, "TODO max num of conn reached; close something" | 935 | //, "TODO max num of conn reached; close something" |
911 | assert(NULL == connection); | 936 | assert(NULL == connection); |
912 | } | 937 | } |
913 | 938 | */ | |
914 | 939 | ||
915 | int | 940 | int |
916 | spdy_get_selectfdset(fd_set * read_fd_set, | 941 | spdy_get_selectfdset(fd_set * read_fd_set, |
@@ -921,7 +946,7 @@ spdy_get_selectfdset(fd_set * read_fd_set, | |||
921 | nfds_t *real_size) | 946 | nfds_t *real_size) |
922 | { | 947 | { |
923 | struct SPDY_Connection *connection; | 948 | struct SPDY_Connection *connection; |
924 | struct Proxy *proxy; | 949 | struct SPDY_Connection *next_connection; |
925 | bool ret; | 950 | bool ret; |
926 | int maxfd = 0; | 951 | int maxfd = 0; |
927 | 952 | ||
@@ -936,14 +961,9 @@ spdy_get_selectfdset(fd_set * read_fd_set, | |||
936 | except_fd_set, glob_opt.spdy_connection); | 961 | except_fd_set, glob_opt.spdy_connection); |
937 | if(!ret) | 962 | if(!ret) |
938 | { | 963 | { |
939 | //PRINT_INFO("TODO drop connection"); | ||
940 | glob_opt.streams_opened -= glob_opt.spdy_connection->streams_opened; | 964 | glob_opt.streams_opened -= glob_opt.spdy_connection->streams_opened; |
941 | 965 | ||
942 | for(proxy = glob_opt.spdy_connection->proxies_head; NULL != proxy; proxy=proxy->next) | 966 | PRINT_INFO("spdy_free_connection in spdy_get_selectfdset"); |
943 | { | ||
944 | DLL_remove(glob_opt.spdy_connection->proxies_head, glob_opt.spdy_connection->proxies_tail, proxy); | ||
945 | proxy->spdy_active = false; | ||
946 | } | ||
947 | spdy_free_connection(glob_opt.spdy_connection); | 967 | spdy_free_connection(glob_opt.spdy_connection); |
948 | glob_opt.spdy_connection = NULL; | 968 | glob_opt.spdy_connection = NULL; |
949 | } | 969 | } |
@@ -963,18 +983,15 @@ spdy_get_selectfdset(fd_set * read_fd_set, | |||
963 | ret = spdy_ctl_select(read_fd_set, | 983 | ret = spdy_ctl_select(read_fd_set, |
964 | write_fd_set, | 984 | write_fd_set, |
965 | except_fd_set, connection); | 985 | except_fd_set, connection); |
986 | |||
987 | next_connection = connection->next; | ||
966 | if(!ret) | 988 | if(!ret) |
967 | { | 989 | { |
968 | //PRINT_INFO("TODO drop connection"); | ||
969 | glob_opt.streams_opened -= connection->streams_opened; | 990 | glob_opt.streams_opened -= connection->streams_opened; |
970 | DLL_remove(glob_opt.spdy_connections_head, glob_opt.spdy_connections_tail, connection); | 991 | DLL_remove(glob_opt.spdy_connections_head, glob_opt.spdy_connections_tail, connection); |
971 | glob_opt.total_spdy_connections--; | 992 | glob_opt.total_spdy_connections--; |
972 | 993 | ||
973 | for(proxy = connection->proxies_head; NULL != proxy; proxy=proxy->next) | 994 | PRINT_INFO("spdy_free_connection in spdy_get_selectfdset"); |
974 | { | ||
975 | DLL_remove(connection->proxies_head, connection->proxies_tail, proxy); | ||
976 | proxy->spdy_active = false; | ||
977 | } | ||
978 | spdy_free_connection(connection); | 995 | spdy_free_connection(connection); |
979 | } | 996 | } |
980 | else | 997 | else |
@@ -983,7 +1000,7 @@ spdy_get_selectfdset(fd_set * read_fd_set, | |||
983 | ++(*real_size); | 1000 | ++(*real_size); |
984 | if(maxfd < connection->fd) maxfd = connection->fd; | 1001 | if(maxfd < connection->fd) maxfd = connection->fd; |
985 | } | 1002 | } |
986 | connection = connection->next; | 1003 | connection = next_connection; |
987 | } | 1004 | } |
988 | 1005 | ||
989 | //, "TODO max num of conn reached; close something" | 1006 | //, "TODO max num of conn reached; close something" |
@@ -992,7 +1009,7 @@ spdy_get_selectfdset(fd_set * read_fd_set, | |||
992 | return maxfd; | 1009 | return maxfd; |
993 | } | 1010 | } |
994 | 1011 | ||
995 | 1012 | /* | |
996 | void | 1013 | void |
997 | spdy_run(struct pollfd fds[], | 1014 | spdy_run(struct pollfd fds[], |
998 | struct SPDY_Connection *connections[], | 1015 | struct SPDY_Connection *connections[], |
@@ -1029,9 +1046,13 @@ spdy_run(struct pollfd fds[], | |||
1029 | } | 1046 | } |
1030 | for(proxy = connections[i]->proxies_head; NULL != proxy; proxy=proxy->next) | 1047 | for(proxy = connections[i]->proxies_head; NULL != proxy; proxy=proxy->next) |
1031 | { | 1048 | { |
1049 | abort(); | ||
1032 | DLL_remove(connections[i]->proxies_head, connections[i]->proxies_tail, proxy); | 1050 | DLL_remove(connections[i]->proxies_head, connections[i]->proxies_tail, proxy); |
1033 | proxy->spdy_active = false; | 1051 | proxy->spdy_active = false; |
1052 | proxy->spdy_error = true; | ||
1053 | PRINT_INFO2("spdy_free_connection for id %i", proxy->id); | ||
1034 | } | 1054 | } |
1055 | PRINT_INFO("spdy_free_connection in loop"); | ||
1035 | spdy_free_connection(connections[i]); | 1056 | spdy_free_connection(connections[i]); |
1036 | } | 1057 | } |
1037 | } | 1058 | } |
@@ -1039,6 +1060,7 @@ spdy_run(struct pollfd fds[], | |||
1039 | PRINT_INFO("not called"); | 1060 | PRINT_INFO("not called"); |
1040 | } | 1061 | } |
1041 | } | 1062 | } |
1063 | */ | ||
1042 | 1064 | ||
1043 | void | 1065 | void |
1044 | spdy_run_select(fd_set * read_fd_set, | 1066 | spdy_run_select(fd_set * read_fd_set, |
@@ -1049,7 +1071,6 @@ spdy_run_select(fd_set * read_fd_set, | |||
1049 | { | 1071 | { |
1050 | int i; | 1072 | int i; |
1051 | int ret; | 1073 | int ret; |
1052 | struct Proxy *proxy; | ||
1053 | 1074 | ||
1054 | for(i=0; i<size; ++i) | 1075 | for(i=0; i<size; ++i) |
1055 | { | 1076 | { |
@@ -1071,11 +1092,7 @@ spdy_run_select(fd_set * read_fd_set, | |||
1071 | DLL_remove(glob_opt.spdy_connections_head, glob_opt.spdy_connections_tail, connections[i]); | 1092 | DLL_remove(glob_opt.spdy_connections_head, glob_opt.spdy_connections_tail, connections[i]); |
1072 | glob_opt.total_spdy_connections--; | 1093 | glob_opt.total_spdy_connections--; |
1073 | } | 1094 | } |
1074 | for(proxy = connections[i]->proxies_head; NULL != proxy; proxy=proxy->next) | 1095 | PRINT_INFO("in spdy_run_select"); |
1075 | { | ||
1076 | DLL_remove(connections[i]->proxies_head, connections[i]->proxies_tail, proxy); | ||
1077 | proxy->spdy_active = false; | ||
1078 | } | ||
1079 | spdy_free_connection(connections[i]); | 1096 | spdy_free_connection(connections[i]); |
1080 | } | 1097 | } |
1081 | } | 1098 | } |