Skip to content

Commit b5963af

Browse files
author
capitalists
authored
Fix DSUController socket option error on Linux (#234)
1 parent 9a60979 commit b5963af

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/input/api/DSU/DSUControllerProvider.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#include "input/api/DSU/DSUControllerProvider.h"
22
#include "input/api/DSU/DSUController.h"
33

4+
#if BOOST_OS_WINDOWS
5+
#include <boost/asio/detail/socket_option.hpp>
6+
#include <winsock2.h>
7+
#elif BOOST_OS_LINUX || BOOST_OS_MACOS
8+
#include <sys/time.h>
9+
#include <sys/socket.h>
10+
#endif
11+
412
DSUControllerProvider::DSUControllerProvider()
513
: base_type(), m_uid(rand()), m_socket(m_io_service)
614
{
@@ -77,9 +85,14 @@ bool DSUControllerProvider::connect()
7785
m_socket.close();
7886

7987
m_socket.open(ip::udp::v4());
80-
// set timeout for our threads to give a chance to exit
81-
m_socket.set_option(boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_RCVTIMEO>{200});
8288

89+
// set timeout for our threads to give a chance to exit
90+
#if BOOST_OS_WINDOWS
91+
m_socket.set_option(boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_RCVTIMEO>{200});
92+
#elif BOOST_OS_LINUX || BOOST_OS_MACOS
93+
timeval timeout{.tv_usec = 200 * 1000};
94+
setsockopt(m_socket.native_handle(), SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeval));
95+
#endif
8396
// reset data
8497
m_state = {};
8598
m_prev_state = {};

0 commit comments

Comments
 (0)