diff options
Diffstat (limited to 'src/examples/mhd2spdy.c')
-rw-r--r-- | src/examples/mhd2spdy.c | 82 |
1 files changed, 21 insertions, 61 deletions
diff --git a/src/examples/mhd2spdy.c b/src/examples/mhd2spdy.c index d921aa27..0426a276 100644 --- a/src/examples/mhd2spdy.c +++ b/src/examples/mhd2spdy.c | |||
@@ -31,16 +31,20 @@ | |||
31 | #include "mhd2spdy_spdy.h" | 31 | #include "mhd2spdy_spdy.h" |
32 | #include "mhd2spdy_http.h" | 32 | #include "mhd2spdy_http.h" |
33 | 33 | ||
34 | |||
34 | static int run = 1; | 35 | static int run = 1; |
35 | //static int spdy_close = 0; | 36 | //static int spdy_close = 0; |
36 | 37 | ||
37 | static void catch_signal(int signal) | 38 | |
39 | static void | ||
40 | catch_signal(int signal) | ||
38 | { | 41 | { |
39 | (void)signal; | 42 | (void)signal; |
40 | //spdy_close = 1; | 43 | //spdy_close = 1; |
41 | run = 0; | 44 | run = 0; |
42 | } | 45 | } |
43 | 46 | ||
47 | |||
44 | int | 48 | int |
45 | run_everything () | 49 | run_everything () |
46 | { | 50 | { |
@@ -54,10 +58,7 @@ run_everything () | |||
54 | int maxfd_s = -1; | 58 | int maxfd_s = -1; |
55 | struct MHD_Daemon *daemon; | 59 | struct MHD_Daemon *daemon; |
56 | nfds_t spdy_npollfds = 1; | 60 | nfds_t spdy_npollfds = 1; |
57 | //struct pollfd spdy_pollfds[MAX_SPDY_CONNECTIONS]; | ||
58 | struct URI * spdy2http_uri = NULL; | 61 | struct URI * spdy2http_uri = NULL; |
59 | //int spdy_nfds; | ||
60 | //int spdylay_timeout = 0; | ||
61 | struct SPDY_Connection *connection; | 62 | struct SPDY_Connection *connection; |
62 | struct SPDY_Connection *connections[MAX_SPDY_CONNECTIONS]; | 63 | struct SPDY_Connection *connections[MAX_SPDY_CONNECTIONS]; |
63 | struct SPDY_Connection *connection_for_delete; | 64 | struct SPDY_Connection *connection_for_delete; |
@@ -68,18 +69,15 @@ run_everything () | |||
68 | if (signal(SIGINT, catch_signal) == SIG_ERR) | 69 | if (signal(SIGINT, catch_signal) == SIG_ERR) |
69 | PRINT_INFO("signal failed"); | 70 | PRINT_INFO("signal failed"); |
70 | 71 | ||
71 | //spdy2http_url = argv[2]; | ||
72 | glob_opt.streams_opened = 0; | 72 | glob_opt.streams_opened = 0; |
73 | glob_opt.responses_pending = 0; | 73 | glob_opt.responses_pending = 0; |
74 | glob_opt.global_memory = 0; | 74 | glob_opt.global_memory = 0; |
75 | //spdy_proto_version = 0; | ||
76 | 75 | ||
77 | srand(time(NULL)); | 76 | srand(time(NULL)); |
78 | 77 | ||
79 | if(init_parse_uri(&glob_opt.uri_preg)) | 78 | if(init_parse_uri(&glob_opt.uri_preg)) |
80 | DIE("Regexp compilation failed"); | 79 | DIE("Regexp compilation failed"); |
81 | 80 | ||
82 | |||
83 | if(NULL != glob_opt.spdy2http_str) | 81 | if(NULL != glob_opt.spdy2http_str) |
84 | { | 82 | { |
85 | ret = parse_uri(&glob_opt.uri_preg, glob_opt.spdy2http_str, &spdy2http_uri); | 83 | ret = parse_uri(&glob_opt.uri_preg, glob_opt.spdy2http_str, &spdy2http_uri); |
@@ -105,12 +103,10 @@ run_everything () | |||
105 | if(NULL==daemon) | 103 | if(NULL==daemon) |
106 | DIE("MHD_start_daemon failed"); | 104 | DIE("MHD_start_daemon failed"); |
107 | 105 | ||
108 | |||
109 | do | 106 | do |
110 | { | 107 | { |
111 | 108 | timeout.tv_sec = 0; | |
112 | timeout.tv_sec = 0; | 109 | timeout.tv_usec = 0; |
113 | timeout.tv_usec = 0; | ||
114 | 110 | ||
115 | if(NULL == glob_opt.spdy_connection && NULL != glob_opt.spdy2http_str) | 111 | if(NULL == glob_opt.spdy_connection && NULL != glob_opt.spdy2http_str) |
116 | { | 112 | { |
@@ -119,32 +115,19 @@ run_everything () | |||
119 | PRINT_INFO("cannot connect to the proxy"); | 115 | PRINT_INFO("cannot connect to the proxy"); |
120 | } | 116 | } |
121 | 117 | ||
122 | //PRINT_INFO("while1"); | ||
123 | FD_ZERO(&rs); | 118 | FD_ZERO(&rs); |
124 | FD_ZERO(&ws); | 119 | FD_ZERO(&ws); |
125 | FD_ZERO(&es); | 120 | FD_ZERO(&es); |
126 | 121 | ||
127 | /*if(glob_opt.spdy_data_received) | 122 | ret = MHD_get_timeout(daemon, &timeoutlong); |
128 | { | 123 | if(MHD_NO == ret || timeoutlong > 5000) |
129 | timeout.tv_sec = 0; | 124 | timeout.tv_sec = 5; |
130 | timeout.tv_usec = 0; | ||
131 | glob_opt.spdy_data_received = false; | ||
132 | } | ||
133 | else{*/ | ||
134 | /*if(glob_opt.responses_pending || glob_opt.streams_opened)// TODO only streams_opened true? | ||
135 | timeout.tv_usec = 0; //return immediately | ||
136 | else | 125 | else |
137 | {*/ | 126 | { |
138 | ret = MHD_get_timeout(daemon, &timeoutlong); | 127 | timeout.tv_sec = timeoutlong / 1000; |
139 | if(MHD_NO == ret || timeoutlong > 5000) | 128 | timeout.tv_usec = (timeoutlong % 1000) * 1000; |
140 | timeout.tv_sec = 5; | 129 | } |
141 | else | 130 | |
142 | { | ||
143 | timeout.tv_sec = timeoutlong / 1000; | ||
144 | timeout.tv_usec = (timeoutlong % 1000) * 1000; | ||
145 | } | ||
146 | //} | ||
147 | //} | ||
148 | if(MHD_NO == MHD_get_fdset (daemon, | 131 | if(MHD_NO == MHD_get_fdset (daemon, |
149 | &rs, | 132 | &rs, |
150 | &ws, | 133 | &ws, |
@@ -160,12 +143,10 @@ else{*/ | |||
160 | &ws, | 143 | &ws, |
161 | &es, | 144 | &es, |
162 | connections, MAX_SPDY_CONNECTIONS, &spdy_npollfds); | 145 | connections, MAX_SPDY_CONNECTIONS, &spdy_npollfds); |
163 | if(maxfd_s > maxfd) maxfd = maxfd_s; | 146 | if(maxfd_s > maxfd) |
147 | maxfd = maxfd_s; | ||
164 | 148 | ||
165 | PRINT_INFO2("MHD timeout %lld %lld", (unsigned long long)timeout.tv_sec, (unsigned long long)timeout.tv_usec); | 149 | PRINT_INFO2("MHD timeout %lld %lld", (unsigned long long)timeout.tv_sec, (unsigned long long)timeout.tv_usec); |
166 | //TODO | ||
167 | //timeout.tv_sec = 0; | ||
168 | //timeout.tv_usec = 0; | ||
169 | 150 | ||
170 | glob_opt.spdy_data_received = false; | 151 | glob_opt.spdy_data_received = false; |
171 | 152 | ||
@@ -181,42 +162,20 @@ else{*/ | |||
181 | break; | 162 | break; |
182 | default: | 163 | default: |
183 | PRINT_INFO("run"); | 164 | PRINT_INFO("run"); |
184 | //MHD_run_from_select(daemon,&rs, &ws, &es); //not closing FDs | 165 | //MHD_run_from_select(daemon,&rs, &ws, &es); //not closing FDs at some time in past |
185 | MHD_run(daemon); | 166 | MHD_run(daemon); |
186 | spdy_run_select(&rs, &ws, &es, connections, spdy_npollfds); | 167 | spdy_run_select(&rs, &ws, &es, connections, spdy_npollfds); |
187 | if(glob_opt.spdy_data_received) | 168 | if(glob_opt.spdy_data_received) |
188 | { | 169 | { |
189 | PRINT_INFO("MHD run again"); | 170 | PRINT_INFO("MHD run again"); |
190 | //MHD_run_from_select(daemon,&rs, &ws, &es); //not closing FDs | 171 | //MHD_run_from_select(daemon,&rs, &ws, &es); //not closing FDs at some time in past |
191 | MHD_run(daemon); | 172 | MHD_run(daemon); |
192 | } | 173 | } |
193 | break; | 174 | break; |
194 | } | 175 | } |
195 | |||
196 | /* | ||
197 | //if(glob_opt.streams_opened) spdylay_timeout = 500; | ||
198 | //if(glob_opt.responses_pending || glob_opt.streams_opened) spdylay_timeout = 0; | ||
199 | //else spdylay_timeout = 0; | ||
200 | //else spdylay_timeout = 0; | ||
201 | |||
202 | spdy_get_pollfdset(spdy_pollfds, connections, MAX_SPDY_CONNECTIONS, &spdy_npollfds); | ||
203 | |||
204 | //TODO | ||
205 | //spdylay_timeout = 0; | ||
206 | |||
207 | PRINT_INFO2("spdylay timeout %i", spdylay_timeout); | ||
208 | ret = poll(spdy_pollfds, spdy_npollfds, spdylay_timeout); | ||
209 | if(ret == -1) | ||
210 | DIE("poll"); | ||
211 | if(ret > 0){ | ||
212 | PRINT_INFO("spdy_run"); | ||
213 | spdy_run(spdy_pollfds, connections, spdy_npollfds); | ||
214 | }*/ | ||
215 | } | 176 | } |
216 | while(run); | 177 | while(run); |
217 | 178 | ||
218 | //TODO exit from loop and clean | ||
219 | |||
220 | MHD_stop_daemon (daemon); | 179 | MHD_stop_daemon (daemon); |
221 | 180 | ||
222 | //TODO SSL_free brakes | 181 | //TODO SSL_free brakes |
@@ -246,6 +205,7 @@ else{*/ | |||
246 | return 0; | 205 | return 0; |
247 | } | 206 | } |
248 | 207 | ||
208 | |||
249 | void | 209 | void |
250 | display_usage() | 210 | display_usage() |
251 | { | 211 | { |