@@ -52,20 +52,19 @@ int main(int argc, char **argv)
5252 }
5353 auto c = hcpp::config::get_config (cfg_path);
5454 c->config_to (hcpp::slow_dns::get_slow_dns ());
55- // c->save_callback([sd = hcpp::slow_dns::get_slow_dns()](auto &&cs)
56- // { sd->save_hm(cs.hm_); });
5755
5856 asio::io_context io_context;
5957
60- hcpp::nc= std::make_shared<hcpp::notify_channel>(io_context,1 );
58+ hcpp::nc = std::make_shared<hcpp::notify_channel>(io_context, 1 );
6159
6260 asio::signal_set signals (io_context, SIGINT, SIGTERM);
6361 signals.async_wait ([&](auto , auto )
6462 { io_context.stop (); });
6563
6664 hcpp::httpserver hs;
6765 hcpp::mimt_https_server mhs;
68- if (!c->config_to (mhs)){
66+ if (!c->config_to (mhs))
67+ {
6968 return -1 ;
7069 }
7170
@@ -76,15 +75,28 @@ int main(int argc, char **argv)
7675 }
7776 return c; });
7877
79- co_spawn (io_context, hs.wait_http (c->get_port ()), detached);
80- co_spawn (io_context, mhs.wait_c (10 ,c->get_proxy_service ()), detached);
81- // co_spawn(io_context, []()->asio::awaitable<void>{co_await hcpp::nc->async_send(asio::error_code{}, "ok");}, detached);
78+ auto exit_handler = [&io_context](auto &&eptr)
79+ {
80+ try
81+ {
82+ if (eptr)
83+ std::rethrow_exception (eptr);
84+ }
85+ catch (const std::exception &e)
86+ {
87+ log::error (" exit_handler: {}" , e.what ());
88+ io_context.stop ();
89+ }
90+ };
91+
92+ co_spawn (io_context, hs.wait_http (c->get_port ()), exit_handler);
93+ co_spawn (io_context, mhs.wait_c (10 , c->get_proxy_service ()), exit_handler);
8294
8395 auto create_thread = [&](auto self, int i) -> void
8496 {
8597 if (i > 0 )
8698 {
87- spdlog::debug (" 线程{}创建成功" ,i);
99+ spdlog::debug (" 线程{}创建成功" , i);
88100 std::jthread j (self, self, i - 1 );
89101 while (!io_context.stopped ())
90102 {
@@ -98,7 +110,7 @@ int main(int argc, char **argv)
98110 }
99111 }
100112 j.join ();
101- spdlog::debug (" 线程{}退出成功" ,i);
113+ spdlog::debug (" 线程{}退出成功" , i);
102114 }
103115 };
104116 // 为了防止对象在多线程情况下销毁出问题
0 commit comments