Don't listen to stdin in accept_connection
Fixes reconnect when server is spawned by systemd
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "accept_connection.h"
|
#include "accept_connection.h"
|
||||||
|
|
||||||
|
#include "util/u_logging.h"
|
||||||
#include "utils/overloaded.h"
|
#include "utils/overloaded.h"
|
||||||
|
|
||||||
#include "wivrn_config.h"
|
#include "wivrn_config.h"
|
||||||
@@ -27,14 +28,13 @@
|
|||||||
|
|
||||||
#include <sys/poll.h>
|
#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_ipc_socket_monado->send(from_monado::headset_disconnected{});
|
||||||
|
|
||||||
wivrn::TCPListener listener(wivrn::default_port);
|
wivrn::TCPListener listener(wivrn::default_port);
|
||||||
|
|
||||||
pollfd fds[3]{
|
pollfd fds[2]{
|
||||||
{.fd = watch_fd, .events = POLLIN},
|
|
||||||
{.fd = listener.get_fd(), .events = POLLIN},
|
{.fd = listener.get_fd(), .events = POLLIN},
|
||||||
{.fd = wivrn_ipc_socket_monado->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)
|
if (fds[0].revents & POLLIN)
|
||||||
return {};
|
|
||||||
|
|
||||||
if (fds[1].revents & POLLIN)
|
|
||||||
{
|
{
|
||||||
wivrn_ipc_socket_monado->send(from_monado::headset_connected{});
|
wivrn_ipc_socket_monado->send(from_monado::headset_connected{});
|
||||||
return std::make_unique<wivrn::TCP>(listener.accept().first);
|
return std::make_unique<wivrn::TCP>(listener.accept().first);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fds[2].revents & POLLIN)
|
if (fds[1].revents & POLLIN)
|
||||||
{
|
{
|
||||||
auto packet = receive_from_main();
|
auto packet = receive_from_main();
|
||||||
if (packet)
|
if (packet)
|
||||||
std::visit(utils::overloaded{
|
std::visit(utils::overloaded{
|
||||||
[](to_monado::stop) {
|
[](to_monado::stop) {
|
||||||
// gets handled in wivrn_session::reconnect since we return nullptr
|
// gets handled in wivrn_session::reconnect since we return nullptr
|
||||||
|
U_LOG_I("Received stop packet during reconnect, stopping");
|
||||||
},
|
},
|
||||||
[](auto &&) {
|
[](auto &&) {
|
||||||
// Ignore request when no headset is connected
|
// Ignore request when no headset is connected
|
||||||
|
|||||||
@@ -25,5 +25,5 @@
|
|||||||
namespace wivrn
|
namespace wivrn
|
||||||
{
|
{
|
||||||
class TCP;
|
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
|
} // namespace wivrn
|
||||||
|
|||||||
@@ -1106,7 +1106,7 @@ void wivrn_session::reconnect()
|
|||||||
}
|
}
|
||||||
|
|
||||||
U_LOG_I("Waiting for new connection");
|
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)
|
if (not tcp)
|
||||||
{
|
{
|
||||||
request_stop();
|
request_stop();
|
||||||
|
|||||||
Reference in New Issue
Block a user