| 1468 | size_t idx = 0; |
| 1469 | while (idx < connections.sizeInElements() and &connections[idx] != &connection) |
| 1470 | { |
| 1471 | idx += 1; |
| 1472 | } |
| 1473 | if (idx == connections.sizeInElements() or connection.state != HttpConnection::State::Inactive) |
| 1474 | { |
| 1475 | return false; |
| 1476 | } |
| 1477 | |
| 1478 | connection.state = HttpConnection::State::Active; |
| 1479 | connectionID.index = idx; |
| 1480 | connection.connectionID = connectionID; |
| 1481 | |
| 1482 | if (idx > highestActiveConnection) |
| 1483 | { |
| 1484 | highestActiveConnection = idx; |
| 1485 | } |
| 1486 | connection.request.setHeaderMemory(connection.getHeaderMemory()); |
| 1487 | connection.response.setHeaderMemory(connection.getHeaderMemory()); |
| 1488 | numConnections++; |
| 1489 | if (numConnections == connections.sizeInElements()) |
| 1490 | { |
| 1491 | // Avoid deadlock by force disabling keep-alive if this is the last connection. |
| 1492 | connection.response.forceDisableKeepAlive = true; |
| 1493 | } |
| 1494 | return true; |
| 1495 | } |
| 1496 | |
| 1497 | bool HttpConnectionsPool::deactivate(HttpConnection::ID connectionID) |
| 1498 | { |
| 1499 | HttpConnection& connection = connections[connectionID.index]; |
| 1500 | if (connection.state == HttpConnection::State::Inactive) |
| 1501 | { |
| 1502 | return false; |
| 1503 | } |
| 1504 | |
| 1505 | connection.reset(); |
| 1506 | numConnections--; |
| 1507 | |
| 1508 | if (numConnections == 0) |
| 1509 | { |
| 1510 | highestActiveConnection = 0; |
| 1511 | } |
| 1512 | else if (connectionID.index == highestActiveConnection) |
no test coverage detected