From b5963afbb5bc606247213997ba1814a19b60b6a7 Mon Sep 17 00:00:00 2001 From: capitalists Date: Sun, 11 Sep 2022 02:20:40 +0000 Subject: [PATCH] Fix DSUController socket option error on Linux (#234) --- src/input/api/DSU/DSUControllerProvider.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/input/api/DSU/DSUControllerProvider.cpp b/src/input/api/DSU/DSUControllerProvider.cpp index 4f48f9e5..345e249f 100644 --- a/src/input/api/DSU/DSUControllerProvider.cpp +++ b/src/input/api/DSU/DSUControllerProvider.cpp @@ -1,6 +1,14 @@ #include "input/api/DSU/DSUControllerProvider.h" #include "input/api/DSU/DSUController.h" +#if BOOST_OS_WINDOWS +#include +#include +#elif BOOST_OS_LINUX || BOOST_OS_MACOS +#include +#include +#endif + DSUControllerProvider::DSUControllerProvider() : base_type(), m_uid(rand()), m_socket(m_io_service) { @@ -77,9 +85,14 @@ bool DSUControllerProvider::connect() m_socket.close(); m_socket.open(ip::udp::v4()); - // set timeout for our threads to give a chance to exit - m_socket.set_option(boost::asio::detail::socket_option::integer{200}); + // set timeout for our threads to give a chance to exit +#if BOOST_OS_WINDOWS + m_socket.set_option(boost::asio::detail::socket_option::integer{200}); +#elif BOOST_OS_LINUX || BOOST_OS_MACOS + timeval timeout{.tv_usec = 200 * 1000}; + setsockopt(m_socket.native_handle(), SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeval)); +#endif // reset data m_state = {}; m_prev_state = {};