diff --git a/server/accept_connection.cpp b/server/accept_connection.cpp index f6b992cf..092676bf 100644 --- a/server/accept_connection.cpp +++ b/server/accept_connection.cpp @@ -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 -std::unique_ptr wivrn::accept_connection(int watch_fd, std::function quit) +std::unique_ptr wivrn::accept_connection(std::function 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::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(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 diff --git a/server/accept_connection.h b/server/accept_connection.h index eeb45102..62365555 100644 --- a/server/accept_connection.h +++ b/server/accept_connection.h @@ -25,5 +25,5 @@ namespace wivrn { class TCP; -std::unique_ptr accept_connection(int watch_fd, std::function quit = std::function()); +std::unique_ptr accept_connection(std::function quit = std::function()); } // namespace wivrn diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index e50b8028..74d1fe50 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -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();