diff options
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r-- | src/microhttpd/daemon.c | 66 |
1 files changed, 29 insertions, 37 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index dbf21e18..a25fe358 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -2174,22 +2174,15 @@ MHD_get_timeout (struct MHD_Daemon *daemon, | |||
2174 | static void | 2174 | static void |
2175 | process_urh (struct MHD_UpgradeResponseHandle *urh) | 2175 | process_urh (struct MHD_UpgradeResponseHandle *urh) |
2176 | { | 2176 | { |
2177 | #if FIXME_BUFFERS | 2177 | /* handle reading from TLS client and writing to application */ |
2178 | // FIXME: we need buffer/buffer_size/buffer_off for | ||
2179 | // both directions to be somehow stored within urh. | ||
2180 | // (Note that despite using the same variable names | ||
2181 | // below, we need actually different buffers for each | ||
2182 | // direction.) | ||
2183 | |||
2184 | /* handle reading from HTTPS client and writing to application */ | ||
2185 | if ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->celi_client)) && | 2178 | if ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->celi_client)) && |
2186 | (buffer_off < buffer_size) ) | 2179 | (urh->in_buffer_off < urh->in_buffer_size) ) |
2187 | { | 2180 | { |
2188 | ssize_t res; | 2181 | ssize_t res; |
2189 | 2182 | ||
2190 | res = gnutls_record_recv (uri->connection->tls_session, | 2183 | res = gnutls_record_recv (urh->connection->tls_session, |
2191 | &buffer[buffer_off], | 2184 | &urh->in_buffer[urh->in_buffer_off], |
2192 | buffer_size - buffer_off); | 2185 | urh->in_buffer_size - urh->in_buffer_off); |
2193 | if ( (GNUTLS_E_AGAIN == res) || | 2186 | if ( (GNUTLS_E_AGAIN == res) || |
2194 | (GNUTLS_E_INTERRUPTED == res) ) | 2187 | (GNUTLS_E_INTERRUPTED == res) ) |
2195 | { | 2188 | { |
@@ -2197,17 +2190,17 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
2197 | } | 2190 | } |
2198 | else if (res > 0) | 2191 | else if (res > 0) |
2199 | { | 2192 | { |
2200 | buffer_off += res; | 2193 | urh->in_buffer_off += res; |
2201 | } | 2194 | } |
2202 | } | 2195 | } |
2203 | if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->celi_mhd)) && | 2196 | if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->celi_mhd)) && |
2204 | (buffer_off > 0) ) | 2197 | (urh->in_buffer_off > 0) ) |
2205 | { | 2198 | { |
2206 | size_t res; | 2199 | size_t res; |
2207 | 2200 | ||
2208 | res = write (urh->mhd_socket, | 2201 | res = write (urh->mhd_socket, |
2209 | buffer, | 2202 | urh->in_buffer, |
2210 | buffer_off); | 2203 | urh->in_buffer_off); |
2211 | if (-1 == res) | 2204 | if (-1 == res) |
2212 | { | 2205 | { |
2213 | /* FIXME: differenciate by errno? */ | 2206 | /* FIXME: differenciate by errno? */ |
@@ -2215,29 +2208,29 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
2215 | } | 2208 | } |
2216 | else | 2209 | else |
2217 | { | 2210 | { |
2218 | if (buffer_off != res) | 2211 | if (urh->in_buffer_off != res) |
2219 | { | 2212 | { |
2220 | memmove (buffer, | 2213 | memmove (urh->in_buffer, |
2221 | &buffer[res], | 2214 | &urh->in_buffer[res], |
2222 | buffer_off - res); | 2215 | urh->in_buffer_off - res); |
2223 | buffer_off -= res; | 2216 | urh->in_buffer_off -= res; |
2224 | } | 2217 | } |
2225 | else | 2218 | else |
2226 | { | 2219 | { |
2227 | buffer_off = 0; | 2220 | urh->in_buffer_off = 0; |
2228 | } | 2221 | } |
2229 | } | 2222 | } |
2230 | } | 2223 | } |
2231 | 2224 | ||
2232 | /* handle reading from application and writing to HTTPS client */ | 2225 | /* handle reading from application and writing to HTTPS client */ |
2233 | if ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->celi_mhd)) && | 2226 | if ( (0 != (MHD_EPOLL_STATE_READ_READY & urh->celi_mhd)) && |
2234 | (buffer_off < buffer_size) ) | 2227 | (urh->out_buffer_off < urh->out_buffer_size) ) |
2235 | { | 2228 | { |
2236 | size_t res; | 2229 | size_t res; |
2237 | 2230 | ||
2238 | res = read (urh->mhd_socket, | 2231 | res = read (urh->mhd_socket, |
2239 | &buffer[buffer_off], | 2232 | &urh->out_buffer[urh->out_buffer_off], |
2240 | buffer_size - buffer_off); | 2233 | urh->out_buffer_size - urh->out_buffer_off); |
2241 | if (-1 == res) | 2234 | if (-1 == res) |
2242 | { | 2235 | { |
2243 | /* FIXME: differenciate by errno? */ | 2236 | /* FIXME: differenciate by errno? */ |
@@ -2245,17 +2238,17 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
2245 | } | 2238 | } |
2246 | else | 2239 | else |
2247 | { | 2240 | { |
2248 | buffer_off += res; | 2241 | urh->out_buffer_off += res; |
2249 | } | 2242 | } |
2250 | } | 2243 | } |
2251 | if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->celi_client)) && | 2244 | if ( (0 != (MHD_EPOLL_STATE_WRITE_READY & urh->celi_client)) && |
2252 | (buffer_off > 0) ) | 2245 | (urh->out_buffer_off > 0) ) |
2253 | { | 2246 | { |
2254 | ssize_t res; | 2247 | ssize_t res; |
2255 | 2248 | ||
2256 | res = gnutls_record_send (uri->connection->tls_session, | 2249 | res = gnutls_record_send (urh->connection->tls_session, |
2257 | buffer, | 2250 | urh->out_buffer, |
2258 | buffer_off); | 2251 | urh->out_buffer_off); |
2259 | if ( (GNUTLS_E_AGAIN == res) || | 2252 | if ( (GNUTLS_E_AGAIN == res) || |
2260 | (GNUTLS_E_INTERRUPTED == res) ) | 2253 | (GNUTLS_E_INTERRUPTED == res) ) |
2261 | { | 2254 | { |
@@ -2263,20 +2256,19 @@ process_urh (struct MHD_UpgradeResponseHandle *urh) | |||
2263 | } | 2256 | } |
2264 | else if (res > 0) | 2257 | else if (res > 0) |
2265 | { | 2258 | { |
2266 | if (buffer_off != res) | 2259 | if (urh->out_buffer_off != res) |
2267 | { | 2260 | { |
2268 | memmove (buffer, | 2261 | memmove (urh->out_buffer, |
2269 | &buffer[res], | 2262 | &urh->out_buffer[res], |
2270 | buffer_off - res); | 2263 | urh->out_buffer_off - res); |
2271 | buffer_off -= res; | 2264 | urh->out_buffer_off -= res; |
2272 | } | 2265 | } |
2273 | else | 2266 | else |
2274 | { | 2267 | { |
2275 | buffer_off = 0; | 2268 | urh->out_buffer_off = 0; |
2276 | } | 2269 | } |
2277 | } | 2270 | } |
2278 | } | 2271 | } |
2279 | #endif | ||
2280 | } | 2272 | } |
2281 | #endif | 2273 | #endif |
2282 | 2274 | ||