Don't listen to stdin in accept_connection

Fixes reconnect when server is spawned by systemd
This commit is contained in:
Sapphire committed 2025-12-31 00:59:36 -06:00
1 parent 727d4fab4d
commit 205c84b273
3 files changed
+7 -9

No files matched your search

+5 -7
View File
@@ -19,6 +19,7 @@
#include "accept_connection.h"
#include "util/u_logging.h"
#include "utils/overloaded.h"
#include "wivrn_config.h"
@@ -27,14 +28,13 @@
#include <sys/poll.h>
std::unique_ptr<wivrn::TCP> wivrn::accept_connection(int watch_fd, std::function<bool()> quit)
std::unique_ptr<wivrn::TCP> wivrn::accept_connection(std::function<bool()> quit)
{
wivrn_ipc_socket_monado->send(from_monado::headset_disconnected{});
wivrn::TCPListener listener(wivrn::default_port);
pollfd fds[3]{
{.fd = watch_fd, .events = POLLIN},
pollfd fds[2]{
{.fd = listener.get_fd(), .events = POLLIN},
{.fd = wivrn_ipc_socket_monado->get_fd(), .events = POLLIN},
};
@@ -48,21 +48,19 @@ std::unique_ptr<wivrn::TCP> wivrn::accept_connection(int watch_fd, std::function
}
if (fds[0].revents & POLLIN)
return {};
if (fds[1].revents & POLLIN)
{
wivrn_ipc_socket_monado->send(from_monado::headset_connected{});
return std::make_unique<wivrn::TCP>(listener.accept().first);
}
if (fds[2].revents & POLLIN)
if (fds[1].revents & POLLIN)
{
auto packet = receive_from_main();
if (packet)
std::visit(utils::overloaded{
[](to_monado::stop) {
// gets handled in wivrn_session::reconnect since we return nullptr
U_LOG_I("Received stop packet during reconnect, stopping");
},
[](auto &&) {
// Ignore request when no headset is connected
+1 -1
View File
@@ -25,5 +25,5 @@
namespace wivrn
{
class TCP;
std::unique_ptr<wivrn::TCP> accept_connection(int watch_fd, std::function<bool()> quit = std::function<bool()>());
std::unique_ptr<wivrn::TCP> accept_connection(std::function<bool()> quit = std::function<bool()>());
} // namespace wivrn
+1 -1
View File
@@ -1106,7 +1106,7 @@ void wivrn_session::reconnect()
}
U_LOG_I("Waiting for new connection");
auto tcp = accept_connection(0 /*stdin*/, [this]() { return quit_if_no_client(xrt_system); });
auto tcp = accept_connection([this]() { return quit_if_no_client(xrt_system); });
if (not tcp)
{
request_stop();