@brief do accept
| 566 | |
| 567 | ///@brief do accept |
| 568 | void WebServer::do_accept() { |
| 569 | acceptor.async_accept( |
| 570 | [this](beast::error_code ec, tcp::socket socket) { |
| 571 | if (!ec) { |
| 572 | // Check connection limit |
| 573 | if (active_connections_.load() >= max_connections_) { |
| 574 | header_print("LOG", "Connection limit reached (" + std::to_string(max_connections_) + "), rejecting new connection"); |
| 575 | // Close the socket and continue accepting |
| 576 | socket.close(); |
| 577 | } else { |
| 578 | // Increment connection counter |
| 579 | active_connections_.fetch_add(1); |
| 580 | |
| 581 | // Create a new session for this connection |
| 582 | auto session = std::make_shared<HttpSession>(std::move(socket), *this); |
| 583 | session->start(cors); |
| 584 | } |
| 585 | } |
| 586 | if (running) { |
| 587 | do_accept(); |
| 588 | } |
| 589 | }); |
| 590 | } |
| 591 | |
| 592 | ///@brief process_next_npu_request Handles one queued NPU task at a time |
| 593 | void WebServer::process_next_npu_request() { |