Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
beef9999 committed Jan 6, 2025
1 parent 0a4ef25 commit 587f3dd
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions common/test/test_throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ static void run_real_socket(const std::shared_ptr<std::atomic<bool>>& 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 {
Expand All @@ -344,20 +345,31 @@ static void run_real_socket(const std::shared_ptr<std::atomic<bool>>& running, c
}
return 0;
};
server->setsockopt<int>(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<int>(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()) {
Expand All @@ -372,6 +384,7 @@ static void run_real_socket(const std::shared_ptr<std::atomic<bool>>& 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()) {
Expand Down

0 comments on commit 587f3dd

Please sign in to comment.