Detect network errors from any socket call

This commit is contained in:
Patrick Nicolas
2026-08-31 19:34:05 +02:00
parent 474e55ba68
commit 9e9fc859f5
2 changed files with 29 additions and 3 deletions
+9 -1
View File
@@ -1065,10 +1065,17 @@ void wivrn_session::run_net(std::stop_token stop)
for (auto & haptics: uinput_handler->read_rumble())
send_stream(std::move(haptics));
}
if (auto locked = net_exception.lock(); *locked)
{
std::exception_ptr ex;
std::swap(ex, *locked);
std::rethrow_exception(ex);
}
}
catch (const std::exception & e)
{
U_LOG_W("Exception in network thread: %s, Session paused.", e.what());
U_LOG_W("Network exception: %s, Session paused.", e.what());
pause_session();
reconnect(stop);
@@ -1265,6 +1272,7 @@ void wivrn_session::reconnect(std::stop_token stop)
}
connection->reset(stop, std::move(*tcp), [this]() { quit_if_no_client(); });
*net_exception.lock() = nullptr;
// validate if headset is compatible with the current session
+20 -2
View File
@@ -117,6 +117,8 @@ class wivrn_session : public xrt_system_devices
std::jthread net_thread;
std::jthread worker_thread;
thread_safe<std::exception_ptr> net_exception;
wivrn_session(std::unique_ptr<wivrn_connection> connection, b_system &);
public:
@@ -200,13 +202,29 @@ public:
template <typename T>
void send_stream(T && packet)
{
connection->send_stream(std::forward<T>(packet));
try
{
connection->send_stream(std::forward<T>(packet));
}
catch (std::exception & e)
{
*net_exception.lock() = std::current_exception();
throw;
}
}
template <typename T>
void send_control(T && packet)
{
connection->send_control(std::forward<T>(packet));
try
{
connection->send_control(std::forward<T>(packet));
}
catch (std::exception & e)
{
*net_exception.lock() = std::current_exception();
throw;
}
}
xrt_result_t push_event(const xrt_session_event &);