From 587f3dd82596521ec8719f95f3f8a1e5db6e3bfa Mon Sep 17 00:00:00 2001 From: Bob Chen Date: Mon, 6 Jan 2025 11:57:09 +0800 Subject: [PATCH] a --- common/test/test_throttle.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/common/test/test_throttle.cpp b/common/test/test_throttle.cpp index c49585a1..39cc5642 100644 --- a/common/test/test_throttle.cpp +++ b/common/test/test_throttle.cpp @@ -333,6 +333,7 @@ static void run_real_socket(const std::shared_ptr>& running, c photon::throttle t(p.limit_bw); uint64_t buf_size = std::max(p.io1.bs, p.io2.bs); auto server = photon::net::new_tcp_socket_server(); + ASSERT_NE(nullptr, server); DEFER(delete server); auto handler = [&, _running=running](photon::net::ISocketStream* sock) -> int { @@ -344,20 +345,31 @@ static void run_real_socket(const std::shared_ptr>& running, c } return 0; }; - server->setsockopt(SOL_SOCKET, SO_REUSEPORT, 1); - server->set_handler(handler); - server->bind_v4any(0); - server->listen(); - server->start_loop(false); + + photon::thread_create11([&] { + int ret; + ret = server->setsockopt(SOL_SOCKET, SO_REUSEPORT, 1); + if (ret) exit(1); + server->set_handler(handler); + ret = server->bind_v4any(0); + if (ret) exit(1); + ret = server->listen(); + if (ret) exit(1); + ret = server->start_loop(true); + if (ret) exit(1); + }); + photon::thread_sleep(1); photon::semaphore sem; auto server_ep = server->getsockname(); auto cli = photon::net::new_tcp_socket_client(); + ASSERT_NE(nullptr, cli); DEFER(delete cli); photon::thread_create11([&, _running=running] { photon::throttle src(p.io1.bw); auto conn = cli->connect(server_ep); + if (!conn) exit(1); DEFER(delete conn); char buf[buf_size]; while (_running->load()) { @@ -372,6 +384,7 @@ static void run_real_socket(const std::shared_ptr>& running, c photon::thread_create11([&, _running=running] { photon::throttle src(p.io2.bw); auto conn = cli->connect(server_ep); + if (!conn) exit(1); DEFER(delete conn); char buf[buf_size]; while (_running->load()) {