Skip to content

Commit 37c3f3d

Browse files
committed
fix static data destroy
1 parent db279af commit 37c3f3d

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ int main(int argc, char **argv)
5555

5656
asio::io_context io_context;
5757

58-
hcpp::nc = std::make_shared<hcpp::notify_channel>(io_context, 1);
59-
6058
asio::signal_set signals(io_context, SIGINT, SIGTERM);
6159
signals.async_wait([&](auto, auto)
6260
{ io_context.stop(); });
@@ -67,6 +65,7 @@ int main(int argc, char **argv)
6765
{
6866
return -1;
6967
}
68+
mhs.set_ch(std::make_shared<hcpp::socket_channel>(io_context, 10));
7069

7170
hs.attach_tunnel([&mhs](auto &&c, auto h, auto s)
7271
{
@@ -90,7 +89,7 @@ int main(int argc, char **argv)
9089
};
9190

9291
co_spawn(io_context, hs.wait_http(c->get_port(),io_context), exit_handler);
93-
co_spawn(io_context, mhs.wait_c(10, c->get_proxy_service()), exit_handler);
92+
co_spawn(io_context, mhs.wait_c(c->get_proxy_service()), exit_handler);
9493

9594
auto create_thread = [&](auto self, int i) -> void
9695
{

src/httpserver.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ namespace hcpp
171171
auto executor = co_await this_coro::executor;
172172

173173
tcp_acceptor acceptor(executor, {ip::tcp::v4(), port});
174-
co_await nc->async_receive();
175174
spdlog::debug("http_server监听端口:{}", acceptor.local_endpoint().port());
176175
http_handler hh;
177176
hh.add_handler("/stop", [&ic](auto &&path)
@@ -202,7 +201,7 @@ namespace hcpp
202201

203202
static thread_local std::unordered_map<std::string, subject_identify> server_subject_map;
204203

205-
awaitable<void> mimt_https_server::wait_c(std::size_t cn, std::vector<proxy_service> ps)
204+
awaitable<void> mimt_https_server::wait_c(std::vector<proxy_service> ps)
206205
{
207206
if (!ca_subject_)
208207
{
@@ -218,9 +217,7 @@ namespace hcpp
218217

219218
const decltype(ps_map) &cr_ps_map = ps_map;
220219
io_context executor;
221-
channel_ = std::make_shared<socket_channel>(co_await this_coro::executor, cn);
222220

223-
co_await nc->async_send(asio::error_code{}, "ok");
224221
// 在当前协程运行
225222
auto https_listener = [c = channel_, cr_ps_map, ca_subject = ca_subject_](io_context &executor) -> awaitable<void>
226223
{
@@ -331,4 +328,9 @@ namespace hcpp
331328
root_verify_store_path_ = root_verify_store_path;
332329
}
333330

331+
void mimt_https_server::set_ch(std::shared_ptr<socket_channel> ch)
332+
{
333+
channel_=ch;
334+
}
335+
334336
} // namespace hcpp

src/httpserver.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ namespace hcpp
8585
class mimt_https_server
8686
{
8787
public:
88-
awaitable<void> wait_c(std::size_t cn, std::vector<proxy_service> ps);
88+
awaitable<void> wait_c(std::vector<proxy_service> ps);
8989
awaitable<void> wait(uint16_t port);
9090

9191
std::optional<std::shared_ptr<tunnel>> find_tunnel(std::string_view svc_host, std::string_view svc_service);
9292

9393
std::set<std::pair<std::string, std::string>> tunnel_set_;
9494

95+
void set_ch(std::shared_ptr<socket_channel> ch);
96+
9597
void set_ca(subject_identify ca_subject);
9698
void set_root_verify_store_path(std::string_view root_verify_store_path);
9799

@@ -103,7 +105,6 @@ namespace hcpp
103105

104106
using notify_channel = asio::use_awaitable_t<>::as_default_on_t<concurrent_channel<void(asio::error_code, std::string)>>;
105107

106-
inline std::shared_ptr<notify_channel> nc;
107108
} // namespace hcpp
108109

109110
#endif /* SRC_HTTPSERVER */

0 commit comments

Comments
 (0)