Changeset 1759
- Timestamp:
- 08/07/08 13:38:21 (5 months ago)
- Files:
-
- cherokee/trunk/ChangeLog (modified) (1 diff)
- cherokee/trunk/cherokee/fdpoll-port.c (modified) (1 diff)
- cherokee/trunk/cherokee/macros.h (modified) (1 diff)
- cherokee/trunk/cherokee/server.c (modified) (4 diffs)
- cherokee/trunk/cherokee/socket.c (modified) (4 diffs)
- cherokee/trunk/cherokee/thread.c (modified) (24 diffs)
- cherokee/trunk/cherokee/thread.h (modified) (1 diff)
- cherokee/trunk/cherokee/util.c (modified) (1 diff)
- cherokee/trunk/cherokee/util.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cherokee/trunk/ChangeLog
r1754 r1759 1 2008-08-07 Alvaro Lopez Ortega <alvaro@alobbs.com> 2 3 * cherokee/macros.h, cherokee/socket.c, cherokee/thread.c, 4 cherokee/thread.h, cherokee/util.c, cherokee/util.h, 5 cherokee/fdpoll-port.c, cherokee/server.c: This patch makes the 6 server to reply a quickly built 503 error page when it is 7 overloaded. This is a very special case because the page is not 8 sent by using the server infrastructure but by punching a 9 pre-built string into the socket and closing it right after it. 10 Additionally, the patch also do some clean-up along the way. 11 1 12 2008-08-06 Alvaro Lopez Ortega <alvaro@alobbs.com> 2 13 cherokee/trunk/cherokee/fdpoll-port.c
r1439 r1759 236 236 _reset (cherokee_fdpoll_port_t *fdp, int fd) 237 237 { 238 UNUSED (fdp); 239 UNUSED (fd); 240 238 241 return ret_ok; 239 242 } cherokee/trunk/cherokee/macros.h
r1674 r1759 164 164 165 165 #define SHOULDNT_HAPPEN \ 166 do { fprintf (stderr, "file %s:%d (%s): this should n't happen\n", \166 do { fprintf (stderr, "file %s:%d (%s): this should not happen\n", \ 167 167 __FILE__, __LINE__, __cherokee_func__); \ 168 168 } while (0) cherokee/trunk/cherokee/server.c
r1754 r1759 763 763 * and thus already open connection. 764 764 */ 765 conns_per_thread = fds_per_thread1 / 2;766 srv->conns_max += conns_per_thread;767 fds_per_thread1 += MAX_LISTEN_FDS;765 conns_per_thread = fds_per_thread1 / 2; 766 srv->conns_max += conns_per_thread; 767 fds_per_thread1 += MAX_LISTEN_FDS; 768 768 769 769 /* Set mean fds per thread. … … 785 785 */ 786 786 if (srv->thread_num == 1) { 787 ret = cherokee_thread_accept_on (srv->main_thread); 788 if (unlikely(ret < ret_ok)) { 789 PRINT_ERROR("cherokee_thread_accept_on failed %d\n", ret); 787 ret = cherokee_fdpoll_add (srv->main_thread->fdpoll, S_SOCKET_FD(srv->socket), 0); 788 if (ret < ret_ok) 790 789 return ret; 790 791 if (srv->tls_enabled) { 792 ret = cherokee_fdpoll_add (srv->main_thread->fdpoll, S_SOCKET_FD(srv->socket_tls), 0); 793 if (ret < ret_ok) 794 return ret; 791 795 } 792 796 } … … 809 813 fds_per_thread1 += 2; 810 814 } 811 conns_per_thread = fds_per_thread1 / 2;812 srv->conns_max += conns_per_thread;813 fds_per_thread1 += MAX_LISTEN_FDS;815 conns_per_thread = fds_per_thread1 / 2; 816 srv->conns_max += conns_per_thread; 817 fds_per_thread1 += MAX_LISTEN_FDS; 814 818 815 819 /* NOTE: mean fds per thread has already been set above. … … 840 844 srv->conns_keepalive_max = srv->conns_max - 6; 841 845 842 /* OK, return.843 */844 846 return ret_ok; 845 847 } cherokee/trunk/cherokee/socket.c
r1754 r1759 501 501 ret_t ret; 502 502 503 /* Sanity check 504 */ 503 505 if (socket->socket < 0) { 504 506 return ret_error; 505 507 } 506 508 509 /* SSL/TLS shutdown 510 */ 507 511 #ifdef HAVE_TLS 508 512 if (socket->is_tls == TLS && socket->session != NULL) { 509 # if defined (HAVE_GNUTLS)513 # ifdef HAVE_GNUTLS 510 514 gnutls_bye (socket->session, GNUTLS_SHUT_WR); 511 515 gnutls_deinit (socket->session); 512 516 socket->session = NULL; 513 517 514 # elif defined(HAVE_OPENSSL)518 # elif defined(HAVE_OPENSSL) 515 519 SSL_shutdown (socket->session); 516 520 517 #endif 518 } 519 #endif /* HAVE_TLS */ 520 521 ret = cherokee_close_fd (socket->socket); 522 521 # endif 522 } 523 #endif 524 525 /* Close the socket 526 */ 527 #ifdef _WIN32 528 re = closesocket (socket->socket); 529 #else 530 ret = cherokee_fd_close (socket->socket); 531 #endif 532 533 /* Clean up 534 */ 523 535 TRACE (ENTRIES",close", "fd=%d is_tls=%d re=%d\n", 524 536 socket->socket, socket->is_tls, (int) ret); … … 607 619 switch (SOCKET_AF(socket)) { 608 620 case AF_INET: 609 #if defined(HAVE_INET_PTON)621 #ifdef HAVE_INET_PTON 610 622 re = inet_pton (AF_INET, host->buf, &SOCKET_SIN_ADDR(socket)); 611 623 if (re <= 0) return ret_error; … … 643 655 ret = cherokee_socket_set_sockaddr (socket, fd, &sa); 644 656 if (unlikely(ret < ret_ok)) { 645 cherokee_ close_fd(fd);657 cherokee_fd_close (fd); 646 658 SOCKET_FD(socket) = -1; 647 659 return ret; … … 692 704 */ 693 705 len = sizeof (cherokee_sockaddr_t); 706 694 707 new_socket = accept (server_socket, &sa->sa, &len); 695 708 if (new_socket < 0) { cherokee/trunk/cherokee/thread.c
r1754 r1759 156 156 n->reuse_list_num = 0; 157 157 n->pending_conns_num = 0; 158 n->is_accepting_conns = false;159 158 160 159 n->fastcgi_servers = NULL; … … 176 175 if (fd_num < conns_max) { 177 176 cherokee_fdpoll_free (n->fdpoll); 178 CHEROKEE_FREE (n);177 CHEROKEE_FREE (n); 179 178 return ret_error; 180 179 } 181 182 /* Number of connections that the thread can accept.183 */184 n->conns_accept = (90 * conns_max / 100);185 if (conns_max > n->conns_accept + 5)186 n->conns_accept = conns_max - 5;187 180 188 181 /* Bogo now stuff … … 1263 1256 } 1264 1257 1258 static void 1259 thread_full_handler (cherokee_thread_t *thd, int srv_socket) 1260 { 1261 ret_t ret; 1262 cherokee_list_t *i; 1263 cherokee_socket_t sock; 1264 size_t read = 0; 1265 cherokee_boolean_t done = false; 1266 cherokee_server_t *srv = THREAD_SRV(thd); 1267 cherokee_buffer_t *tmp = THREAD_TMP_BUF1(thd); 1268 1269 /* Short path: nothing to accept 1270 */ 1271 if (cherokee_fdpoll_check (thd->fdpoll, srv_socket, FDPOLL_MODE_READ) <= 0) { 1272 return; 1273 } 1274 1275 /* Check all the threads 1276 */ 1277 list_for_each (i, &srv->thread_list) { 1278 if (THREAD(i)->conns_num < THREAD(i)->conns_max) 1279 return; 1280 } 1281 1282 if (srv->main_thread->conns_num < srv->main_thread->conns_max) 1283 return; 1284 1285 /* In case there is no room in the entire server. The best 1286 * thing we can do reached this point is to get rid of the 1287 * connection as soon and quickly as possible. 1288 */ 1289 ret = cherokee_socket_init (&sock); 1290 if (unlikely (ret != ret_ok)) 1291 goto out; 1292 1293 /* Accept a connection 1294 */ 1295 do { 1296 ret = cherokee_socket_accept (&sock, srv_socket); 1297 } while (ret == ret_deny); 1298 1299 if (ret != ret_ok) 1300 goto out; 1301 1302 /* Read the request 1303 */ 1304 #if 0 1305 do { 1306 ret = cherokee_socket_read (&sock, tmp->buf, tmp->size, &read); 1307 } while (ret == ret_eagain); 1308 #endif 1309 1310 /* Write the error response 1311 */ 1312 cherokee_buffer_clean (tmp); 1313 cherokee_buffer_add_str ( 1314 tmp, 1315 "HTTP/1.0 " http_service_unavailable_string CRLF_CRLF \ 1316 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">" CRLF \ 1317 "<html><head><title>" http_service_unavailable_string \ 1318 "</title></head><body><h1>" http_service_unavailable_string \ 1319 "</h1><p>Server run out of resources.</p></body></html>"); 1320 do { 1321 read = 0; 1322 1323 ret = cherokee_socket_bufwrite (&sock, tmp, &read); 1324 switch (ret) { 1325 case ret_ok: 1326 if (read > 0) { 1327 cherokee_buffer_move_to_begin (tmp, read); 1328 } 1329 default: 1330 done = true; 1331 } 1332 1333 if (cherokee_buffer_is_empty (tmp)) 1334 done = true; 1335 } while (!done); 1336 1337 out: 1338 cherokee_socket_close (&sock); 1339 cherokee_socket_mrproper (&sock); 1340 } 1265 1341 1266 1342 static int 1267 __accept_from_server(cherokee_thread_t *thd, int srv_socket, cherokee_socket_type_t tls)1343 accept_new_connection (cherokee_thread_t *thd, int srv_socket, cherokee_socket_type_t tls) 1268 1344 { 1269 1345 ret_t ret; … … 1272 1348 cherokee_connection_t *new_conn; 1273 1349 1274 /* Return if there're too many or no new connections 1275 */ 1276 if (thd->conns_num >= thd->conns_max) 1277 return 0; 1278 1350 /* Check whether there are connections waiting 1351 */ 1279 1352 if (cherokee_fdpoll_check (thd->fdpoll, srv_socket, FDPOLL_MODE_READ) <= 0) { 1280 1353 return 0; … … 1295 1368 if (unlikely(ret < ret_ok)) { 1296 1369 PRINT_ERROR_S ("ERROR: Trying to get a new connection object\n"); 1297 cherokee_ close_fd(new_fd);1370 cherokee_fd_close (new_fd); 1298 1371 return 0; 1299 1372 } … … 1341 1414 /* Close new socket and reset its socket fd to default value. 1342 1415 */ 1343 cherokee_ close_fd(new_fd);1416 cherokee_fd_close (new_fd); 1344 1417 SOCKET_FD(&new_conn->socket) = -1; 1345 1418 … … 1356 1429 1357 1430 static int 1358 __should_accept_more_from_server(cherokee_thread_t *thd, int re)1431 should_accept_more (cherokee_thread_t *thd, int re) 1359 1432 { 1360 1433 const uint32_t recalculate_steps = 10; … … 1364 1437 if (unlikely (thd->conns_num >= thd->conns_max)) 1365 1438 return 0; 1366 1367 1439 #if 0 1368 1440 if (unlikely (cherokee_fdpoll_is_full(thd->fdpoll))) { … … 1399 1471 1400 1472 ret_t 1401 cherokee_thread_accept_on (cherokee_thread_t *thd)1402 {1403 ret_t ret;1404 1405 if (thd->is_accepting_conns)1406 return ret_ok;1407 1408 /* Add server sockets to polling set.1409 */1410 ret = cherokee_fdpoll_add (thd->fdpoll,1411 S_SOCKET_FD(THREAD_SRV(thd)->socket), FDPOLL_MODE_READ);1412 if (unlikely(ret < ret_ok))1413 return ret;1414 1415 #ifdef HAVE_TLS1416 if (THREAD_SRV(thd)->tls_enabled) {1417 ret = cherokee_fdpoll_add (thd->fdpoll,1418 S_SOCKET_FD(THREAD_SRV(thd)->socket_tls), FDPOLL_MODE_READ);1419 if (unlikely(ret < ret_ok))1420 return ret;1421 }1422 #endif /* HAVE_TLS */1423 1424 /* Set flag and return.1425 */1426 thd->is_accepting_conns = true;1427 1428 return ret_ok;1429 }1430 1431 1432 ret_t1433 cherokee_thread_accept_off (cherokee_thread_t *thd)1434 {1435 ret_t ret;1436 1437 if (!thd->is_accepting_conns)1438 return ret_ok;1439 1440 /* Remove server sockets from polling set.1441 */1442 ret = cherokee_fdpoll_del (thd->fdpoll,1443 S_SOCKET_FD(THREAD_SRV(thd)->socket));1444 if (unlikely(ret < ret_ok))1445 return ret;1446 1447 #ifdef HAVE_TLS1448 if (THREAD_SRV(thd)->tls_enabled) {1449 ret = cherokee_fdpoll_del (thd->fdpoll,1450 S_SOCKET_FD(THREAD_SRV(thd)->socket_tls));1451 if (unlikely(ret < ret_ok))1452 return ret;1453 }1454 #endif /* HAVE_TLS */1455 1456 /* Set flag and return.1457 */1458 thd->is_accepting_conns = false;1459 1460 return ret_ok;1461 }1462 1463 1464 ret_t1465 1473 cherokee_thread_step_SINGLE_THREAD (cherokee_thread_t *thd) 1466 1474 { 1467 1475 int re; 1468 ret_t ret;1476 cherokee_boolean_t accepting; 1469 1477 cherokee_server_t *srv = THREAD_SRV(thd); 1470 1478 int fdwatch_msecs = srv->fdwatch_msecs; … … 1475 1483 1476 1484 /* Reset the server socket. 1477 * cherokee_fdpoll_reset (thd->fdpoll, S_SOCKET_FD(srv->socket)); 1478 */ 1479 1480 /* If the thread is full of connections, it should not 1481 * get new connections. 1482 */ 1483 if (thd->conns_num >= thd->conns_max) { 1484 if (thd->is_accepting_conns) 1485 ret = cherokee_thread_accept_off (thd); 1486 } 1487 else if (thd->conns_num < thd->conns_accept) { 1488 if (!thd->is_accepting_conns) 1489 ret = cherokee_thread_accept_on (thd); 1490 } 1491 1485 * // cherokee_fdpoll_reset (thd->fdpoll, S_SOCKET_FD(srv->socket)); 1486 */ 1492 1487 #if 0 1493 1488 if (unlikely (cherokee_fdpoll_is_full (thd->fdpoll))) { … … 1508 1503 goto out; 1509 1504 1510 do { 1511 re = __accept_from_server (thd, S_SOCKET_FD(srv->socket), non_TLS); 1512 } while (__should_accept_more_from_server (thd, re)); 1513 1505 /* If the thread is full of connections, it should not 1506 * get new connections. 1507 */ 1508 accepting = (thd->conns_num < thd->conns_max); 1509 if (accepting) { 1510 do { 1511 re = accept_new_connection (thd, S_SOCKET_FD(srv->socket), non_TLS); 1512 } while (should_accept_more (thd, re)); 1513 1514 1514 #ifdef HAVE_TLS 1515 if (srv->tls_enabled) { 1516 do { 1517 re = __accept_from_server (thd, S_SOCKET_FD(srv->socket_tls), TLS); 1518 } while (__should_accept_more_from_server (thd, re)); 1519 } 1520 #endif /* HAVE_TLS */ 1515 if (srv->tls_enabled) { 1516 do { 1517 re = accept_new_connection (thd, S_SOCKET_FD(srv->socket_tls), TLS); 1518 } while (should_accept_more (thd, re)); 1519 } 1520 #endif 1521 } else { 1522 thread_full_handler (thd, S_SOCKET_FD(srv->socket)); 1523 if (srv->tls_enabled) { 1524 thread_full_handler (thd, S_SOCKET_FD(srv->socket_tls)); 1525 } 1526 } 1521 1527 1522 1528 out: … … 1536 1542 step_MULTI_THREAD_block (cherokee_thread_t *thd, int socket, pthread_mutex_t *mutex, int fdwatch_msecs) 1537 1543 { 1538 int re; 1539 ret_t ret; 1540 1541 /* In this case, thd->is_accepting_conns is alwasy true. 1542 */ 1544 int re; 1545 ret_t ret; 1546 cherokee_boolean_t accepting; 1547 1543 1548 CHEROKEE_MUTEX_LOCK (mutex); 1544 1549 … … 1560 1565 update_bogo_now (thd); 1561 1566 1562 do { 1563 re = __accept_from_server (thd, socket, non_TLS); 1564 } while (__should_accept_more_from_server (thd, re)); 1565 1567 /* Accept a new connection 1568 */ 1569 accepting = (thd->conns_num < thd->conns_max); 1570 if (accepting) { 1571 do { 1572 re = accept_new_connection (thd, socket, non_TLS); 1573 } while (should_accept_more (thd, re)); 1574 } else { 1575 thread_full_handler (thd, socket); 1576 } 1577 1578 /* Release the socket 1579 */ 1566 1580 ret = cherokee_fdpoll_del (thd->fdpoll, socket); 1567 1581 if (ret != ret_ok) 1568 1582 SHOULDNT_HAPPEN; 1569 1583 1570 CHEROKEE_MUTEX_UNLOCK (mutex); 1571 1584 CHEROKEE_MUTEX_UNLOCK (mutex); 1572 1585 return ret_ok; 1573 1586 } … … 1577 1590 step_MULTI_THREAD_nonblock (cherokee_thread_t *thd, int socket, pthread_mutex_t *mutex, int fdwatch_msecs) 1578 1591 { 1579 int re; 1580 ret_t ret; 1581 int unlocked = 1; 1582 1583 if (thd->is_accepting_conns) { 1584 /* Try to lock 1585 */ 1586 unlocked = CHEROKEE_MUTEX_TRY_LOCK (mutex); 1587 } 1588 1592 ret_t ret; 1593 int re; 1594 cherokee_boolean_t accepting; 1595 int unlocked = 1; 1596 1597 /* Try to lock. Not success: wait for an event to happen 1598 */ 1599 unlocked = CHEROKEE_MUTEX_TRY_LOCK (mutex); 1589 1600 if (unlocked) { 1590 1601 cherokee_fdpoll_watch (thd->fdpoll, fdwatch_msecs); … … 1592 1603 } 1593 1604 1594 /* Now it owns the socket .1605 /* Now it owns the socket 1595 1606 */ 1596 1607 ret = cherokee_fdpoll_add (thd->fdpoll, socket, FDPOLL_MODE_READ); 1597 1608 if (unlikely (ret < ret_ok)) { 1598 CHEROKEE_MUTEX_UNLOCK (mutex); 1599 return ret_error; 1600 } 1601 /* cherokee_fdpoll_reset (thd->fdpoll, socket); 1602 */ 1609 ret = ret_error; 1610 goto out; 1611 } 1612 1603 1613 cherokee_fdpoll_watch (thd->fdpoll, fdwatch_msecs); 1604 1614 1605 do { 1606 re = __accept_from_server (thd, socket, non_TLS); 1607 } while (__should_accept_more_from_server (thd, re)); 1608 1615 /* It should either accept o discard a connection 1616 */ 1617 accepting = (thd->conns_num < thd->conns_max); 1618 if (accepting) { 1619 do { 1620 re = accept_new_connection (thd, socket, non_TLS); 1621 } while (should_accept_more (thd, re)); 1622 1623 } else { 1624 thread_full_handler (thd, socket); 1625 } 1626 1627 /* Release the server socket 1628 */ 1609 1629 ret = cherokee_fdpoll_del (thd->fdpoll, socket); 1610 1630 if (ret != ret_ok) 1611 1631 SHOULDNT_HAPPEN; 1612 1632 1633 ret = ret_ok; 1634 1635 out: 1613 1636 CHEROKEE_MUTEX_UNLOCK (mutex); 1614 1615 return ret_ok; 1637 return ret; 1638 1616 1639 } 1617 1640 … … 1623 1646 int socket_tls, pthread_mutex_t *mutex_tls) 1624 1647 { 1625 int re; 1626 ret_t ret; 1627 int unlock = 1; 1628 int unlock_tls = 1; 1629 1630 if (thd->is_accepting_conns) { 1631 /* Try to lock the mutex 1632 */ 1633 unlock = CHEROKEE_MUTEX_TRY_LOCK (mutex); 1634 } 1635 if (!unlock) { 1648 ret_t ret; 1649 int re; 1650 cherokee_boolean_t accepting; 1651 int unlocked = 1; 1652 int unlocked_tls = 1; 1653 1654 /* Try to lock both mutexes 1655 */ 1656 unlocked = CHEROKEE_MUTEX_TRY_LOCK (mutex); 1657 if (! unlocked) { 1636 1658 ret = cherokee_fdpoll_add (thd->fdpoll, socket, FDPOLL_MODE_READ); 1637 if (ret < ret_ok) { 1638 goto error; 1639 } 1640 /* cherokee_fdpoll_reset (thd->fdpoll, socket); 1641 */ 1642 } 1643 1644 if (thd->is_accepting_conns) { 1645 /* Try to lock the TLS mutex 1646 */ 1647 unlock_tls = CHEROKEE_MUTEX_TRY_LOCK (mutex_tls); 1648 } 1649 if (!unlock_tls) { 1659 if (unlikely (ret < ret_ok)) { 1660 ret = ret_error; 1661 goto out; 1662 } 1663 } 1664 1665 /* Try to lock the TLS mutex 1666 */ 1667 unlocked_tls = CHEROKEE_MUTEX_TRY_LOCK (mutex_tls); 1668 if (!unlocked_tls) { 1650 1669 ret = cherokee_fdpoll_add (thd->fdpoll, socket_tls, FDPOLL_MODE_READ); 1651 if (unlikely (ret < ret_ok)) 1652 goto error; 1653 1654 /* cherokee_fdpoll_reset (thd->fdpoll, socket_tls); 1655 */ 1656 } 1657 1658 /* Inspect the fds and maybe sleep 1670 if (unlikely (ret < ret_ok)) { 1671 ret = ret_error; 1672 goto out; 1673 } 1674 } 1675 1676 /* Inspect the fds. It may sleep if nothing happens 1659 1677 */ 1660 1678 cherokee_fdpoll_watch (thd->fdpoll, fdwatch_msecs); 1661 1679 1662 /* Restore.. 1663 */ 1664 if (!unlock) { 1665 do { 1666 re = __accept_from_server (thd, socket, non_TLS); 1667 } while (__should_accept_more_from_server (thd, re)); 1680 /* accept o discard a connections 1681 */ 1682 accepting = (thd->conns_num < thd->conns_max); 1683 if (accepting) { 1684 if (!unlocked) { 1685 do { 1686 re = accept_new_connection (thd, socket, non_TLS); 1687 } while (should_accept_more (thd, re)); 1668 1688 1669 ret = cherokee_fdpoll_del (thd->fdpoll, socket); 1670 if (ret != ret_ok) 1671 SHOULDNT_HAPPEN; 1689 ret = cherokee_fdpoll_del (thd->fdpoll, socket); 1690 if (ret != ret_ok) 1691 SHOULDNT_HAPPEN; 1692 } 1693 1694 if (!unlocked_tls) { 1695 do { 1696 re = accept_new_connection (thd, socket_tls, TLS); 1697 } while (should_accept_more (thd, re)); 1698 1699 ret = cherokee_fdpoll_del (thd->fdpoll, socket_tls); 1700 if (ret != ret_ok) 1701 SHOULDNT_HAPPEN; 1702 } 1703 1704 } else { 1705 if (!unlocked) 1706 thread_full_handler (thd, socket); 1707 1708 if (!unlocked_tls) 1709 thread_full_handler (thd, socket_tls); 1710 } 1711 1712 ret = ret_ok; 1713 1714 out: 1715 if (!unlocked) 1672 1716 CHEROKEE_MUTEX_UNLOCK (mutex); 1673 } 1674 1675 if (!unlock_tls) { 1676 do { 1677 re = __accept_from_server (thd, socket_tls, TLS); 1678 } while (__should_accept_more_from_server (thd, re)); 1679 1680 ret = cherokee_fdpoll_del (thd->fdpoll, socket_tls); 1681 if (ret != ret_ok) 1682 SHOULDNT_HAPPEN; 1717 if (!unlocked_tls) 1683 1718 CHEROKEE_MUTEX_UNLOCK (mutex_tls); 1684 } 1685 1686 return ret_ok; 1687 1688 1689 error: 1690 if (!unlock) CHEROKEE_MUTEX_UNLOCK (mutex); 1691 if (!unlock_tls) CHEROKEE_MUTEX_UNLOCK (mutex_tls); 1692 1693 return ret_error; 1719 1720 return ret; 1694 1721 } 1695 1722 … … 1707 1734 cherokee_socket_type_t type1; 1708 1735 cherokee_socket_type_t type2; 1736 cherokee_boolean_t accepting; 1709 1737 1710 1738 if (thd->thread_pref == thread_tls_normal) { … … 1726 1754 } 1727 1755 1728 /* In this case, thd->is_accepting_conns is alwasy true.1729 */1730 1731 1756 /* Lock the main mutex 1732 1757 */ … … 1738 1763 return ret_error; 1739 1764 } 1740 /* cherokee_fdpoll_reset (thd->fdpoll, socket1); 1741 */ 1765 1766 /* cherokee_fdpoll_reset (thd->fdpoll, socket1); */ 1767 1742 1768 1743 1769 /* Try to lock the optional groups … … 1762 1788 1763 1789 /* Update the thread time values before accept new connections. 1764 * This ensure a good timeout value for it.1790 * This ensures an updated timeout value for it. 1765 1791 */ 1766 1792 update_bogo_now (thd); 1767 1793 1768 do { 1769 re = __accept_from_server (thd, socket1, type1); 1770 } while (__should_accept_more_from_server (thd, re)); 1794 /* Accept / Discard connection 1795 */ 1796 accepting = (thd->conns_num < thd->conns_max); 1797 if (accepting) { 1798 do { 1799 re = accept_new_connection (thd, socket1, type1); 1800 } while (should_accept_more (thd, re)); 1801 } else { 1802 thread_full_handler (thd, socket1); 1803 } 1771 1804 1772 1805 /* Unlock the mail lock … … 1783 1816 if (!unlock2) { 1784 1817 do { 1785 re = __accept_from_server(thd, socket2, type2);1786 } while ( __should_accept_more_from_server(thd, re));1818 re = accept_new_connection (thd, socket2, type2); 1819 } while (should_accept_more (thd, re)); 1787 1820 1788 1821 ret = cherokee_fdpoll_del (thd->fdpoll, socket2); … … 1806 1839 int fdwatch_msecs = srv->fdwatch_msecs; 1807 1840 1808 1809 1841 /* Try to update bogo_now 1810 1842 */ 1811 1843 cherokee_bogotime_try_update(); 1812 1813 /* If the thread is full of connections, it should not1814 * get new connections.1815 */1816 if (thd->conns_num >= thd->conns_max) {1817 if (thd->is_accepting_conns)1818 thd->is_accepting_conns = false;1819 }1820 else if (thd->conns_num < thd->conns_accept) {1821 if (!thd->is_accepting_conns)1822 thd->is_accepting_conns = true;1823 }1824 1844 1825 1845 #if 0 … … 1841 1861 */ 1842 1862 if (srv->tls_enabled) { 1843 if ((thd->exit == false) && 1863 if ((!dont_block) && 1864 (thd->exit == false) && 1844 1865 (thd->active_list_num == 0) && 1845 (thd->polling_list_num == 0) && (!dont_block)) { 1866 (thd->polling_list_num == 0)) 1867 { 1846 1868 step_MULTI_THREAD_TLS_block (thd, fdwatch_msecs, 1847 S_SOCKET_FD(srv->socket), &THREAD_SRV(thd)->accept_mutex,1869 S_SOCKET_FD(srv->socket), &THREAD_SRV(thd)->accept_mutex, 1848 1870 S_SOCKET_FD(srv->socket_tls), &THREAD_SRV(thd)->accept_tls_mutex); 1849 1871 } else { 1850 1872 step_MULTI_THREAD_TLS_nonblock (thd, fdwatch_msecs, 1851 S_SOCKET_FD(srv->socket), &THREAD_SRV(thd)->accept_mutex,1873 S_SOCKET_FD(srv->socket), &THREAD_SRV(thd)->accept_mutex, 1852 1874 S_SOCKET_FD(srv->socket_tls), &THREAD_SRV(thd)->accept_tls_mutex); 1853 1875 } … … 1859 1881 /* Try to get new connections from http 1860 1882 */ 1861 if ((thd->exit == false) && 1883 if ((!dont_block) && 1884 (thd->exit == false) && 1862 1885 (thd->active_list_num == 0) && 1863 (thd->polling_list_num == 0) && (!dont_block)) { 1864 step_MULTI_THREAD_block (thd, S_SOCKET_FD(srv->socket), &THREAD_SRV(thd)->accept_mutex, fdwatch_msecs); 1886 (thd->polling_list_num == 0)) 1887 { 1888 step_MULTI_THREAD_block (thd, S_SOCKET_FD(srv->socket), 1889 &THREAD_SRV(thd)->accept_mutex, fdwatch_msecs); 1865 1890 } else { 1866 step_MULTI_THREAD_nonblock (thd, S_SOCKET_FD(srv->socket), &THREAD_SRV(thd)->accept_mutex, fdwatch_msecs); 1891 step_MULTI_THREAD_nonblock (thd, S_SOCKET_FD(srv->socket), 1892 &THREAD_SRV(thd)->accept_mutex, fdwatch_msecs); 1867 1893 } 1868 1894 cherokee/trunk/cherokee/thread.h
r1673 r1759 75 75 cherokee_boolean_t exit; 76 76 77 cherokee_boolean_t is_accepting_conns; /* true=accepts new conns */78 79 77 int conns_num; /* open connections */ 80 int conns_max; /* max. connections */ 81 int conns_accept; /* accept limit */ 78 int conns_max; /* max opened conns */ 82 79 83 80 int active_list_num; /* active connections */ cherokee/trunk/cherokee/util.c
r1754 r1759 1242 1242 1243 1243 ret_t 1244 cherokee_ close_fd (cint_t fd)1244 cherokee_fd_close (int fd) 1245 1245 { 1246 1246 int re; 1247 1247 1248 if ( fd < 0) {1248 if (unlikely (fd < 0)) { 1249 1249 return ret_error; 1250 1250 } cherokee/trunk/cherokee/util.h
r1754 r1759 111 111 ret_t cherokee_fd_set_nodelay (int fd, cherokee_boolean_t enable); 112 112 ret_t cherokee_fd_set_closexec (int fd); 113 ret_t cherokee_fd_close (int fd); 113 114 114 115 ret_t cherokee_sys_fdlimit_get (cuint_t *limit); 115 116 ret_t cherokee_sys_fdlimit_set (cuint_t limit); 116 ret_t cherokee_close_fd (cint_t fd);117 117 ret_t cherokee_get_shell (const char **shell, const char **binary); 118 118 void cherokee_print_wrapped (cherokee_buffer_t *buffer);