diff options
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r-- | src/daemon/daemon.c | 97 |
1 files changed, 65 insertions, 32 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 72619c3d..bdd9f87b 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -1329,7 +1329,66 @@ MHD_get_timeout (struct MHD_Daemon *daemon, | |||
1329 | 1329 | ||
1330 | 1330 | ||
1331 | /** | 1331 | /** |
1332 | * Main select call. | 1332 | * Run webserver operations. This method should be called by clients |
1333 | * in combination with MHD_get_fdset if the client-controlled select | ||
1334 | * method is used. | ||
1335 | * | ||
1336 | * You can use this function instead of "MHD_run" if you called | ||
1337 | * 'select' on the result from "MHD_get_fdset". File descriptors in | ||
1338 | * the sets that are not controlled by MHD will be ignored. Calling | ||
1339 | * this function instead of "MHD_run" is more efficient as MHD will | ||
1340 | * not have to call 'select' again to determine which operations are | ||
1341 | * ready. | ||
1342 | * | ||
1343 | * @param daemon daemon to run select loop for | ||
1344 | * @param read_fd_set read set | ||
1345 | * @param write_fd_set write set | ||
1346 | * @param except_fd_set except set (not used, can be NULL) | ||
1347 | * @return MHD_NO on serious errors, MHD_YES on success | ||
1348 | */ | ||
1349 | int | ||
1350 | MHD_run_from_select (struct MHD_Daemon *daemon, | ||
1351 | const fd_set *read_fd_set, | ||
1352 | const fd_set *write_fd_set, | ||
1353 | const fd_set *except_fd_set) | ||
1354 | { | ||
1355 | int ds; | ||
1356 | struct MHD_Connection *pos; | ||
1357 | struct MHD_Connection *next; | ||
1358 | |||
1359 | /* select connection thread handling type */ | ||
1360 | if ( (-1 != (ds = daemon->socket_fd)) && | ||
1361 | (FD_ISSET (ds, read_fd_set)) ) | ||
1362 | MHD_accept_connection (daemon); | ||
1363 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | ||
1364 | { | ||
1365 | /* do not have a thread per connection, process all connections now */ | ||
1366 | next = daemon->connections_head; | ||
1367 | while (NULL != (pos = next)) | ||
1368 | { | ||
1369 | next = pos->next; | ||
1370 | ds = pos->socket_fd; | ||
1371 | if (ds != -1) | ||
1372 | { | ||
1373 | if ( (FD_ISSET (ds, read_fd_set)) | ||
1374 | #if HTTPS_SUPPORT | ||
1375 | || (MHD_YES == pos->tls_read_ready) | ||
1376 | #endif | ||
1377 | ) | ||
1378 | pos->read_handler (pos); | ||
1379 | if (FD_ISSET (ds, write_fd_set)) | ||
1380 | pos->write_handler (pos); | ||
1381 | pos->idle_handler (pos); | ||
1382 | } | ||
1383 | } | ||
1384 | } | ||
1385 | return MHD_YES; | ||
1386 | } | ||
1387 | |||
1388 | |||
1389 | /** | ||
1390 | * Main internal select call. Will compute select sets, call 'select' | ||
1391 | * and then MHD_run_from_select with the result. | ||
1333 | * | 1392 | * |
1334 | * @param daemon daemon to run select loop for | 1393 | * @param daemon daemon to run select loop for |
1335 | * @param may_block YES if blocking, NO if non-blocking | 1394 | * @param may_block YES if blocking, NO if non-blocking |
@@ -1339,8 +1398,6 @@ static int | |||
1339 | MHD_select (struct MHD_Daemon *daemon, | 1398 | MHD_select (struct MHD_Daemon *daemon, |
1340 | int may_block) | 1399 | int may_block) |
1341 | { | 1400 | { |
1342 | struct MHD_Connection *pos; | ||
1343 | struct MHD_Connection *next; | ||
1344 | int num_ready; | 1401 | int num_ready; |
1345 | fd_set rs; | 1402 | fd_set rs; |
1346 | fd_set ws; | 1403 | fd_set ws; |
@@ -1349,7 +1406,6 @@ MHD_select (struct MHD_Daemon *daemon, | |||
1349 | struct timeval timeout; | 1406 | struct timeval timeout; |
1350 | struct timeval *tv; | 1407 | struct timeval *tv; |
1351 | MHD_UNSIGNED_LONG_LONG ltimeout; | 1408 | MHD_UNSIGNED_LONG_LONG ltimeout; |
1352 | int ds; | ||
1353 | 1409 | ||
1354 | timeout.tv_sec = 0; | 1410 | timeout.tv_sec = 0; |
1355 | timeout.tv_usec = 0; | 1411 | timeout.tv_usec = 0; |
@@ -1404,7 +1460,6 @@ MHD_select (struct MHD_Daemon *daemon, | |||
1404 | tv = &timeout; | 1460 | tv = &timeout; |
1405 | } | 1461 | } |
1406 | num_ready = SELECT (max + 1, &rs, &ws, &es, tv); | 1462 | num_ready = SELECT (max + 1, &rs, &ws, &es, tv); |
1407 | |||
1408 | if (MHD_YES == daemon->shutdown) | 1463 | if (MHD_YES == daemon->shutdown) |
1409 | return MHD_NO; | 1464 | return MHD_NO; |
1410 | if (num_ready < 0) | 1465 | if (num_ready < 0) |
@@ -1416,33 +1471,7 @@ MHD_select (struct MHD_Daemon *daemon, | |||
1416 | #endif | 1471 | #endif |
1417 | return MHD_NO; | 1472 | return MHD_NO; |
1418 | } | 1473 | } |
1419 | /* select connection thread handling type */ | 1474 | return MHD_run_from_select (daemon, &rs, &ws, &es); |
1420 | if ( (-1 != (ds = daemon->socket_fd)) && | ||
1421 | (FD_ISSET (ds, &rs)) ) | ||
1422 | MHD_accept_connection (daemon); | ||
1423 | if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | ||
1424 | { | ||
1425 | /* do not have a thread per connection, process all connections now */ | ||
1426 | next = daemon->connections_head; | ||
1427 | while (NULL != (pos = next)) | ||
1428 | { | ||
1429 | next = pos->next; | ||
1430 | ds = pos->socket_fd; | ||
1431 | if (ds != -1) | ||
1432 | { | ||
1433 | if ( (FD_ISSET (ds, &rs)) | ||
1434 | #if HTTPS_SUPPORT | ||
1435 | || (MHD_YES == pos->tls_read_ready) | ||
1436 | #endif | ||
1437 | ) | ||
1438 | pos->read_handler (pos); | ||
1439 | if (FD_ISSET (ds, &ws)) | ||
1440 | pos->write_handler (pos); | ||
1441 | pos->idle_handler (pos); | ||
1442 | } | ||
1443 | } | ||
1444 | } | ||
1445 | return MHD_YES; | ||
1446 | } | 1475 | } |
1447 | 1476 | ||
1448 | 1477 | ||
@@ -1647,6 +1676,10 @@ MHD_poll (struct MHD_Daemon *daemon, | |||
1647 | * by clients in combination with MHD_get_fdset | 1676 | * by clients in combination with MHD_get_fdset |
1648 | * if the client-controlled select method is used. | 1677 | * if the client-controlled select method is used. |
1649 | * | 1678 | * |
1679 | * This function will work for external 'poll' and 'select' mode. | ||
1680 | * However, if using external 'select' mode, you may want to | ||
1681 | * instead use 'MHD_run_from_select', as it is more efficient. | ||
1682 | * | ||
1650 | * @return MHD_YES on success, MHD_NO if this | 1683 | * @return MHD_YES on success, MHD_NO if this |
1651 | * daemon was not started with the right | 1684 | * daemon was not started with the right |
1652 | * options for this call. | 1685 | * options for this call. |