Use ipc_server_stop to exit during reconnect
This commit is contained in:
@@ -19,8 +19,6 @@
|
||||
|
||||
#include "accept_connection.h"
|
||||
|
||||
#include "server/ipc_server_interface.h"
|
||||
|
||||
#include "utils/overloaded.h"
|
||||
|
||||
#include "wivrn_config.h"
|
||||
@@ -29,7 +27,7 @@
|
||||
|
||||
#include <sys/poll.h>
|
||||
|
||||
std::unique_ptr<wivrn::TCP> wivrn::accept_connection(ipc_server * server, int watch_fd, std::function<bool()> quit)
|
||||
std::unique_ptr<wivrn::TCP> wivrn::accept_connection(int watch_fd, std::function<bool()> quit)
|
||||
{
|
||||
wivrn_ipc_socket_monado->send(from_monado::headset_disconnected{});
|
||||
|
||||
@@ -63,8 +61,8 @@ std::unique_ptr<wivrn::TCP> wivrn::accept_connection(ipc_server * server, int wa
|
||||
auto packet = receive_from_main();
|
||||
if (packet)
|
||||
std::visit(utils::overloaded{
|
||||
[server](to_monado::stop) {
|
||||
ipc_server_stop(server);
|
||||
[](to_monado::stop) {
|
||||
// gets handled in wivrn_session::reconnect since we return nullptr
|
||||
},
|
||||
[](auto &&) {
|
||||
// Ignore request when no headset is connected
|
||||
|
||||
@@ -19,13 +19,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "server/ipc_server.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class TCP;
|
||||
std::unique_ptr<wivrn::TCP> accept_connection(ipc_server * server, int watch_fd, std::function<bool()> quit = std::function<bool()>());
|
||||
std::unique_ptr<wivrn::TCP> accept_connection(int watch_fd, std::function<bool()> quit = std::function<bool()>());
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -419,6 +419,14 @@ void wivrn_session::stop()
|
||||
thread = std::jthread();
|
||||
}
|
||||
|
||||
bool wivrn_session::request_stop()
|
||||
{
|
||||
assert(mnd_ipc_server);
|
||||
bool b = thread.request_stop();
|
||||
ipc_server_stop(mnd_ipc_server);
|
||||
return b;
|
||||
}
|
||||
|
||||
clock_offset wivrn_session::get_offset()
|
||||
{
|
||||
return offset_est.get_offset();
|
||||
@@ -959,8 +967,7 @@ void wivrn_session::operator()(audio_data && data)
|
||||
|
||||
void wivrn_session::operator()(to_monado::stop &&)
|
||||
{
|
||||
assert(mnd_ipc_server);
|
||||
ipc_server_stop(mnd_ipc_server);
|
||||
request_stop();
|
||||
}
|
||||
|
||||
void wivrn_session::operator()(to_monado::disconnect &&)
|
||||
@@ -1078,7 +1085,7 @@ static bool quit_if_no_client(u_system & xrt_system)
|
||||
return false;
|
||||
}
|
||||
U_LOG_I("No OpenXR client connected, exiting");
|
||||
exit(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void wivrn_session::reconnect()
|
||||
@@ -1099,9 +1106,12 @@ void wivrn_session::reconnect()
|
||||
}
|
||||
|
||||
U_LOG_I("Waiting for new connection");
|
||||
auto tcp = accept_connection(mnd_ipc_server, 0 /*stdin*/, [this]() { return quit_if_no_client(xrt_system); });
|
||||
auto tcp = accept_connection(0 /*stdin*/, [this]() { return quit_if_no_client(xrt_system); });
|
||||
if (not tcp)
|
||||
exit(0);
|
||||
{
|
||||
request_stop();
|
||||
return;
|
||||
}
|
||||
|
||||
struct no_client_connected
|
||||
{};
|
||||
@@ -1136,7 +1146,7 @@ void wivrn_session::reconnect()
|
||||
catch (no_client_connected)
|
||||
{
|
||||
U_LOG_I("No OpenXR application connected");
|
||||
exit(0);
|
||||
request_stop();
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
|
||||
@@ -161,6 +161,8 @@ public:
|
||||
void start(ipc_server *);
|
||||
void stop();
|
||||
|
||||
bool request_stop();
|
||||
|
||||
clock_offset get_offset();
|
||||
bool connected();
|
||||
const from_headset::headset_info_packet & get_info() const
|
||||
|
||||
Reference in New Issue
Block a user