aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2020-10-11 17:53:06 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2020-10-11 17:53:06 +0300
commitae49c200af866f3be80a0538e2c428cdcd7e3010 (patch)
treed578227161f5e2346c8e5323eb92daa24a28229e
parentf0d4dde902692968ef34f93796d05b1417d92dae (diff)
downloadlibmicrohttpd-ae49c200af866f3be80a0538e2c428cdcd7e3010.tar.gz
libmicrohttpd-ae49c200af866f3be80a0538e2c428cdcd7e3010.zip
MHD_add_connection: small refactoring
-rw-r--r--src/microhttpd/daemon.c59
1 files changed, 30 insertions, 29 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 5a7c0caa..ca488593 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2376,38 +2376,11 @@ internal_add_connection (struct MHD_Daemon *daemon,
2376 bool non_blck) 2376 bool non_blck)
2377{ 2377{
2378 struct MHD_Connection *connection; 2378 struct MHD_Connection *connection;
2379#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2380 unsigned int i;
2381#endif
2382 int eno = 0; 2379 int eno = 0;
2383 2380
2384 /* Direct add to master daemon could happen only with "external" add mode. */
2385#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS) 2381#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
2386 mhd_assert ((NULL == daemon->worker_pool) || (external_add)); 2382 /* Direct add to master daemon could never happen. */
2387 if ((external_add) && (NULL != daemon->worker_pool)) 2383 mhd_assert ((NULL == daemon->worker_pool));
2388 {
2389 /* have a pool, try to find a pool with capacity; we use the
2390 socket as the initial offset into the pool for load
2391 balancing */
2392 for (i = 0; i < daemon->worker_pool_size; ++i)
2393 {
2394 struct MHD_Daemon *const worker =
2395 &daemon->worker_pool[(i + client_socket) % daemon->worker_pool_size];
2396 if (worker->connections < worker->connection_limit)
2397 return internal_add_connection (worker,
2398 client_socket,
2399 addr,
2400 addrlen,
2401 true,
2402 non_blck);
2403 }
2404 /* all pools are at their connection limit, must refuse */
2405 MHD_socket_close_chk_ (client_socket);
2406#if ENFILE
2407 errno = ENFILE;
2408#endif
2409 return MHD_NO;
2410 }
2411#endif 2384#endif
2412 2385
2413 if ( (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL))) && 2386 if ( (0 == (daemon->options & (MHD_USE_POLL | MHD_USE_EPOLL))) &&
@@ -3184,6 +3157,34 @@ MHD_add_connection (struct MHD_Daemon *daemon,
3184 _ ("Failed to reset buffering mode on new client socket.\n")); 3157 _ ("Failed to reset buffering mode on new client socket.\n"));
3185#endif 3158#endif
3186 } 3159 }
3160#if defined(MHD_USE_POSIX_THREADS) || defined(MHD_USE_W32_THREADS)
3161 if (NULL != daemon->worker_pool)
3162 {
3163 unsigned int i;
3164 /* have a pool, try to find a pool with capacity; we use the
3165 socket as the initial offset into the pool for load
3166 balancing */
3167 for (i = 0; i < daemon->worker_pool_size; ++i)
3168 {
3169 struct MHD_Daemon *const worker =
3170 &daemon->worker_pool[(i + client_socket) % daemon->worker_pool_size];
3171 if (worker->connections < worker->connection_limit)
3172 return internal_add_connection (worker,
3173 client_socket,
3174 addr,
3175 addrlen,
3176 true,
3177 sk_nonbl);
3178 }
3179 /* all pools are at their connection limit, must refuse */
3180 MHD_socket_close_chk_ (client_socket);
3181#if ENFILE
3182 errno = ENFILE;
3183#endif
3184 return MHD_NO;
3185 }
3186#endif /* MHD_USE_POSIX_THREADS || MHD_USE_W32_THREADS */
3187
3187 return internal_add_connection (daemon, 3188 return internal_add_connection (daemon,
3188 client_socket, 3189 client_socket,
3189 addr, 3190 addr,