| 46 | } |
| 47 | |
| 48 | void accept_loop() { |
| 49 | while (!_accept_loop_handle.canceled()) { |
| 50 | fc::tcp_socket* connection_socket = new fc::tcp_socket; |
| 51 | _server_socket.accept(*connection_socket); |
| 52 | ilog("Got new connection from ${remote}", ("remote", connection_socket->remote_endpoint())); |
| 53 | |
| 54 | auto worker_thread = get_worker(); |
| 55 | if (worker_thread == nullptr) { |
| 56 | connection_socket->close(); |
| 57 | delete connection_socket; |
| 58 | continue; |
| 59 | } |
| 60 | auto finished_future = worker_thread->async([=]{serve_client(connection_socket); }, "serve_client"); |
| 61 | auto master_thread = &fc::thread::current(); |
| 62 | |
| 63 | finished_future.on_complete([=](fc::exception_ptr ep) { master_thread->async([=] { |
| 64 | _busy_threads.erase(worker_thread); |
| 65 | if ((int)_idle_threads.size() < _target_thread_count) { |
| 66 | _idle_threads.insert(worker_thread); |
| 67 | ilog("Resting thread; there are now ${i} idle and ${b} busy", ("i", _idle_threads.size())("b", _busy_threads.size())); |
| 68 | } |
| 69 | else |
| 70 | kill_worker(worker_thread); |
| 71 | }, "cleanup_chain_server_threads"); }); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void handle_get_blocks_from_number(fc::tcp_socket& connection_socket) { |
| 76 | try { |
nothing calls this directly
no test coverage detected