| 836 | } |
| 837 | |
| 838 | std::thread server_models::setup_child_server(const std::function<void(int)> & shutdown_handler) { |
| 839 | // send a notification to the router server that a model instance is ready |
| 840 | common_log_pause(common_log_main()); |
| 841 | fflush(stdout); |
| 842 | fprintf(stdout, "%s\n", CMD_CHILD_TO_ROUTER_READY); |
| 843 | fflush(stdout); |
| 844 | common_log_resume(common_log_main()); |
| 845 | |
| 846 | // setup thread for monitoring stdin |
| 847 | return std::thread([shutdown_handler]() { |
| 848 | // wait for EOF on stdin |
| 849 | SRV_INF("%s", "child server monitoring thread started, waiting for EOF on stdin...\n"); |
| 850 | bool eof = false; |
| 851 | while (true) { |
| 852 | std::string line; |
| 853 | if (!std::getline(std::cin, line)) { |
| 854 | // EOF detected, that means the router server is unexpectedly exit or killed |
| 855 | eof = true; |
| 856 | break; |
| 857 | } |
| 858 | if (line.find(CMD_ROUTER_TO_CHILD_EXIT) != std::string::npos) { |
| 859 | SRV_INF("%s", "exit command received, exiting...\n"); |
| 860 | shutdown_handler(0); |
| 861 | break; |
| 862 | } |
| 863 | } |
| 864 | if (eof) { |
| 865 | SRV_INF("%s", "EOF on stdin detected, forcing shutdown...\n"); |
| 866 | exit(1); |
| 867 | } |
| 868 | }); |
| 869 | } |
| 870 | |
| 871 | void server_models::notify_router_sleeping_state(bool is_sleeping) { |
| 872 | common_log_pause(common_log_main()); |
nothing calls this directly
no test coverage detected