| 431 | } |
| 432 | |
| 433 | int accept_loop() { |
| 434 | if (workth) LOG_ERROR_RETURN(EALREADY, -1, "Already listening"); |
| 435 | workth = photon::CURRENT; |
| 436 | DEFER(workth = nullptr); |
| 437 | while (workth) { |
| 438 | waiting = true; |
| 439 | auto connection = accept(); |
| 440 | waiting = false; |
| 441 | if (!workth) return 0; |
| 442 | if (connection) { |
| 443 | connection->timeout(m_timeout); |
| 444 | photon::thread_create11(&KernelSocketServer::handler, m_handler, connection); |
| 445 | } else { |
| 446 | LOG_WARN("KernelSocketServer: failed to accept new connections: `", ERRNO()); |
| 447 | photon::thread_usleep(1000); |
| 448 | } |
| 449 | } |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | static void handler(Handler m_handler, ISocketStream* sess) { |
| 454 | m_handler(sess); |
nothing calls this directly
no test coverage detected