Skip to content

Commit

Permalink
stability fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cnbatch committed Oct 27, 2024
1 parent b96cfae commit 54422b6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
int main(int argc, char *argv[])
{
#ifdef __cpp_lib_format
std::cout << std::format("{} version 20241026\n", app_name);
std::cout << std::format("{} version 20241027\n", app_name);
if (argc <= 1)
{
std::cout << std::format("Usage: {} config1.conf\n", app_name);
std::cout << std::format(" {} config1.conf config2.conf...\n", (int)app_name.length(), app_name.data());
return 0;
}
#else
std::cout << app_name << " version 20241026\n";
std::cout << app_name << " version 20241027\n";
if (argc <= 1)
{
std::cout << "Usage: " << app_name << " config1.conf\n";
Expand Down
4 changes: 2 additions & 2 deletions src/networks/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,11 @@ void client_mode::cleanup_expiring_forwarders()
int64_t time_elapsed = calculate_difference(time_right_now, expire_time);

if (time_elapsed > CLEANUP_WAITS / 3 &&
time_elapsed <= CLEANUP_WAITS / 3 * 2 &&
time_elapsed <= CLEANUP_WAITS * 2 / 3 &&
forwarder_ptr != nullptr)
forwarder_ptr->pause(true);

if (time_elapsed > CLEANUP_WAITS / 3 * 2 &&
if (time_elapsed > CLEANUP_WAITS * 2 / 3 &&
forwarder_ptr != nullptr)
forwarder_ptr->stop();

Expand Down
12 changes: 9 additions & 3 deletions src/networks/connections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void udp_server::handle_receive(std::unique_ptr<uint8_t[]> buffer_cache, const a
{
if (error)
{
if (!connection_socket.is_open())
if (error == asio::error::operation_aborted || !connection_socket.is_open())
return;
}

Expand Down Expand Up @@ -396,6 +396,9 @@ void udp_client::pause(bool set_as_pause)

void udp_client::stop()
{
bool expect = true;
if (stopped.compare_exchange_strong(expect, true))
return;
stopped.store(true);
callback = empty_udp_callback;
if (connection_socket.is_open())
Expand Down Expand Up @@ -544,7 +547,10 @@ void udp_client::start_receive()

std::unique_ptr<uint8_t[]> buffer_cache = std::make_unique<uint8_t[]>(BUFFER_SIZE);
uint8_t *buffer_raw_ptr = buffer_cache.get();
connection_socket.async_receive_from(asio::buffer(buffer_raw_ptr, BUFFER_SIZE), incoming_endpoint,
auto asio_buffer = asio::buffer(buffer_raw_ptr, BUFFER_SIZE);
if (!connection_socket.is_open())
return;
connection_socket.async_receive_from(asio_buffer, incoming_endpoint,
[buffer = std::move(buffer_cache), this](const asio::error_code &error, std::size_t bytes_transferred) mutable
{
handle_receive(std::move(buffer), error, bytes_transferred);
Expand All @@ -555,7 +561,7 @@ void udp_client::handle_receive(std::unique_ptr<uint8_t[]> buffer_cache, const a
{
if (error)
{
if (!stopped.load() && !paused.load() && connection_socket.is_open())
if (error != asio::error::operation_aborted && !stopped.load() && !paused.load() && connection_socket.is_open())
start_receive();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/networks/relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,11 @@ void relay_mode::cleanup_expiring_data_connections()
std::shared_ptr<forwarder> egress_forwarder = std::atomic_load(&udp_session_ptr->egress_forwarder);

if (time_elapsed > CLEANUP_WAITS / 3 &&
time_elapsed <= CLEANUP_WAITS / 3 * 2 &&
time_elapsed <= CLEANUP_WAITS * 2 / 3 &&
egress_forwarder != nullptr)
egress_forwarder->pause(true);

if (time_elapsed > CLEANUP_WAITS / 3 * 2 &&
if (time_elapsed > CLEANUP_WAITS * 2 / 3 &&
egress_forwarder != nullptr)
egress_forwarder->stop();

Expand Down

0 comments on commit 54422b6

Please sign in to comment.