mirror of
https://github.com/cemu-project/Cemu.git
synced 2026-07-10 01:24:41 -06:00
Fix DSUController on Linux
This commit is contained in:
parent
cf598e38c1
commit
b0e523a44e
@ -43,6 +43,7 @@ target_sources(CemuInput PRIVATE
|
||||
api/DSU/DSUControllerProvider.h
|
||||
api/DSU/DSUMessages.h
|
||||
api/DSU/DSUMessages.cpp
|
||||
api/DSU/TimeoutSocketOption.h
|
||||
)
|
||||
|
||||
# Keyboard controller
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "input/api/DSU/DSUControllerProvider.h"
|
||||
#include "input/api/DSU/DSUController.h"
|
||||
#include "input/api/DSU/TimeoutSocketOption.h"
|
||||
|
||||
DSUControllerProvider::DSUControllerProvider()
|
||||
: base_type(), m_uid(rand()), m_socket(m_io_service)
|
||||
@ -77,8 +78,9 @@ 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<SOL_SOCKET, SO_RCVTIMEO>{200});
|
||||
m_socket.set_option(TimeoutSocketOption{200});
|
||||
|
||||
// reset data
|
||||
m_state = {};
|
||||
|
||||
40
src/input/api/DSU/TimeoutSocketOption.h
Normal file
40
src/input/api/DSU/TimeoutSocketOption.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#if BOOST_OS_WINDOWS
|
||||
#include <boost/asio/detail/socket_option.hpp>
|
||||
#include <winsock2.h> // For SOL_SOCKET, SO_RCVTIMEO
|
||||
using TimeoutSocketOption = boost::asio::detail::socket_option::integer<SOL_SOCKET, SO_RCVTIMEO>;
|
||||
#elif BOOST_OS_LINUX || BOOST_OS_MACOS
|
||||
|
||||
// For making RCVTIME0 work on Linux and probably Mac too
|
||||
class TimeoutSocketOption {
|
||||
timeval m_data;
|
||||
public:
|
||||
constexpr explicit TimeoutSocketOption(int time_ms)
|
||||
: m_data(timeval{.tv_usec = time_ms * 1000}){
|
||||
}
|
||||
TimeoutSocketOption& operator=(int time_ms){
|
||||
m_data = timeval{.tv_usec = time_ms * 1000};
|
||||
return *this;
|
||||
}
|
||||
template <typename Protocol>
|
||||
int level(const Protocol&) const {
|
||||
return SOL_SOCKET;
|
||||
}
|
||||
|
||||
template <typename Protocol>
|
||||
int name(const Protocol&) const {
|
||||
return SO_RCVTIMEO;
|
||||
}
|
||||
|
||||
template <typename Protocol>
|
||||
const timeval* data(Protocol&) const {
|
||||
return &m_data;
|
||||
}
|
||||
|
||||
template <typename Protocol>
|
||||
std::size_t size(const Protocol&) const {
|
||||
return sizeof(timeval);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user