aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/response.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/response.c')
-rw-r--r--src/microhttpd/response.c107
1 files changed, 62 insertions, 45 deletions
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index d3bf1ab7..159c8ecb 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -1962,9 +1962,6 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
1962#ifdef HTTPS_SUPPORT 1962#ifdef HTTPS_SUPPORT
1963 if (0 != (daemon->options & MHD_USE_TLS) ) 1963 if (0 != (daemon->options & MHD_USE_TLS) )
1964 { 1964 {
1965 struct MemoryPool *pool;
1966 size_t avail;
1967 char *buf;
1968 MHD_socket sv[2]; 1965 MHD_socket sv[2];
1969#if defined(MHD_socket_nosignal_) || ! defined(MHD_socket_pair_nblk_) 1966#if defined(MHD_socket_nosignal_) || ! defined(MHD_socket_pair_nblk_)
1970 int res1; 1967 int res1;
@@ -2037,54 +2034,12 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
2037 free (urh); 2034 free (urh);
2038 return MHD_NO; 2035 return MHD_NO;
2039 } 2036 }
2040 pool = connection->pool;
2041 if (0 != connection->write_buffer_size)
2042 {
2043 mhd_assert (NULL != connection->write_buffer);
2044 /* All data should be sent already */
2045 mhd_assert (connection->write_buffer_send_offset == \
2046 connection->write_buffer_append_offset);
2047 (void) MHD_pool_reallocate (pool, connection->write_buffer,
2048 connection->write_buffer_size, 0);
2049 connection->write_buffer_append_offset = 0;
2050 connection->write_buffer_send_offset = 0;
2051 connection->write_buffer_size = 0;
2052 }
2053 connection->write_buffer = NULL;
2054 urh->app.socket = sv[0]; 2037 urh->app.socket = sv[0];
2055 urh->app.urh = urh; 2038 urh->app.urh = urh;
2056 urh->app.celi = MHD_EPOLL_STATE_UNREADY; 2039 urh->app.celi = MHD_EPOLL_STATE_UNREADY;
2057 urh->mhd.socket = sv[1]; 2040 urh->mhd.socket = sv[1];
2058 urh->mhd.urh = urh; 2041 urh->mhd.urh = urh;
2059 urh->mhd.celi = MHD_EPOLL_STATE_UNREADY; 2042 urh->mhd.celi = MHD_EPOLL_STATE_UNREADY;
2060 avail = MHD_pool_get_free (pool);
2061 if (avail < RESERVE_EBUF_SIZE)
2062 {
2063 /* connection's pool is totally at the limit,
2064 use our 'emergency' buffer of #RESERVE_EBUF_SIZE bytes. */
2065 avail = RESERVE_EBUF_SIZE;
2066 buf = urh->e_buf;
2067#ifdef HAVE_MESSAGES
2068 MHD_DLOG (daemon,
2069 _ ("Memory shortage in connection's memory pool. " \
2070 "The \"upgraded\" communication will be inefficient.\n"));
2071#endif
2072 }
2073 else
2074 {
2075 /* Normal case: grab all remaining memory from the
2076 connection's pool for the IO buffers; the connection
2077 certainly won't need it anymore as we've upgraded
2078 to another protocol. */
2079 buf = MHD_pool_allocate (pool,
2080 avail,
2081 false);
2082 }
2083 /* use half the buffer for inbound, half for outbound */
2084 urh->in_buffer_size = avail / 2;
2085 urh->out_buffer_size = avail - urh->in_buffer_size;
2086 urh->in_buffer = buf;
2087 urh->out_buffer = &buf[urh->in_buffer_size];
2088#ifdef EPOLL_SUPPORT 2043#ifdef EPOLL_SUPPORT
2089 /* Launch IO processing by the event loop */ 2044 /* Launch IO processing by the event loop */
2090 if (0 != (daemon->options & MHD_USE_EPOLL)) 2045 if (0 != (daemon->options & MHD_USE_EPOLL))
@@ -2185,6 +2140,68 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
2185 connection->socket_fd, 2140 connection->socket_fd,
2186#endif /* ! HTTPS_SUPPORT */ 2141#endif /* ! HTTPS_SUPPORT */
2187 urh); 2142 urh);
2143
2144#ifdef HTTPS_SUPPORT
2145 if (0 != (daemon->options & MHD_USE_TLS))
2146 {
2147 struct MemoryPool *const pool = connection->pool;
2148 size_t avail;
2149 char *buf;
2150
2151 if (0 != connection->write_buffer_size)
2152 {
2153 mhd_assert (NULL != connection->write_buffer);
2154 /* All data should be sent already */
2155 mhd_assert (connection->write_buffer_send_offset == \
2156 connection->write_buffer_append_offset);
2157 (void) MHD_pool_reallocate (pool, connection->write_buffer,
2158 connection->write_buffer_size, 0);
2159 connection->write_buffer_append_offset = 0;
2160 connection->write_buffer_send_offset = 0;
2161 connection->write_buffer_size = 0;
2162 }
2163 connection->write_buffer = NULL;
2164
2165 if (0 != connection->read_buffer_size)
2166 {
2167 mhd_assert (NULL != connection->read_buffer);
2168 (void) MHD_pool_reallocate (pool, connection->read_buffer,
2169 connection->read_buffer_size, 0);
2170 connection->read_buffer_offset = 0;
2171 connection->read_buffer_size = 0;
2172 }
2173 connection->read_buffer = NULL;
2174
2175 avail = MHD_pool_get_free (pool);
2176 if (avail < RESERVE_EBUF_SIZE)
2177 {
2178 /* connection's pool is totally at the limit,
2179 use our 'emergency' buffer of #RESERVE_EBUF_SIZE bytes. */
2180 avail = RESERVE_EBUF_SIZE;
2181 buf = urh->e_buf;
2182#ifdef HAVE_MESSAGES
2183 MHD_DLOG (daemon,
2184 _ ("Memory shortage in connection's memory pool. " \
2185 "The \"upgraded\" communication will be inefficient.\n"));
2186#endif
2187 }
2188 else
2189 {
2190 /* Normal case: grab all remaining memory from the
2191 connection's pool for the IO buffers; the connection
2192 certainly won't need it anymore as we've upgraded
2193 to another protocol. */
2194 buf = MHD_pool_allocate (pool,
2195 avail,
2196 false);
2197 }
2198 /* use half the buffer for inbound, half for outbound */
2199 urh->in_buffer_size = avail / 2;
2200 urh->out_buffer_size = avail - urh->in_buffer_size;
2201 urh->in_buffer = buf;
2202 urh->out_buffer = buf + urh->in_buffer_size;
2203 }
2204#endif /* HTTPS_SUPPORT */
2188 return MHD_YES; 2205 return MHD_YES;
2189} 2206}
2190 2207