diff options
Diffstat (limited to 'src/input_common/udp/client.cpp')
| -rw-r--r-- | src/input_common/udp/client.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 2228571a6..da5227058 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp | |||
| @@ -32,8 +32,16 @@ public: | |||
| 32 | SocketCallback callback) | 32 | SocketCallback callback) |
| 33 | : callback(std::move(callback)), timer(io_service), | 33 | : callback(std::move(callback)), timer(io_service), |
| 34 | socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(client_id), | 34 | socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(client_id), |
| 35 | pad_index(pad_index), | 35 | pad_index(pad_index) { |
| 36 | send_endpoint(udp::endpoint(boost::asio::ip::make_address_v4(host), port)) {} | 36 | boost::system::error_code ec{}; |
| 37 | auto ipv4 = boost::asio::ip::make_address_v4(host, ec); | ||
| 38 | if (ec.value() != boost::system::errc::success) { | ||
| 39 | LOG_ERROR(Input, "Invalid IPv4 address \"{}\" provided to socket", host); | ||
| 40 | ipv4 = boost::asio::ip::address_v4{}; | ||
| 41 | } | ||
| 42 | |||
| 43 | send_endpoint = {udp::endpoint(ipv4, port)}; | ||
| 44 | } | ||
| 37 | 45 | ||
| 38 | void Stop() { | 46 | void Stop() { |
| 39 | io_service.stop(); | 47 | io_service.stop(); |
| @@ -85,17 +93,18 @@ private: | |||
| 85 | } | 93 | } |
| 86 | 94 | ||
| 87 | void HandleSend(const boost::system::error_code& error) { | 95 | void HandleSend(const boost::system::error_code& error) { |
| 96 | boost::system::error_code _ignored{}; | ||
| 88 | // Send a request for getting port info for the pad | 97 | // Send a request for getting port info for the pad |
| 89 | Request::PortInfo port_info{1, {pad_index, 0, 0, 0}}; | 98 | Request::PortInfo port_info{1, {pad_index, 0, 0, 0}}; |
| 90 | const auto port_message = Request::Create(port_info, client_id); | 99 | const auto port_message = Request::Create(port_info, client_id); |
| 91 | std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE); | 100 | std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE); |
| 92 | socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint); | 101 | socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint, {}, _ignored); |
| 93 | 102 | ||
| 94 | // Send a request for getting pad data for the pad | 103 | // Send a request for getting pad data for the pad |
| 95 | Request::PadData pad_data{Request::PadData::Flags::Id, pad_index, EMPTY_MAC_ADDRESS}; | 104 | Request::PadData pad_data{Request::PadData::Flags::Id, pad_index, EMPTY_MAC_ADDRESS}; |
| 96 | const auto pad_message = Request::Create(pad_data, client_id); | 105 | const auto pad_message = Request::Create(pad_data, client_id); |
| 97 | std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE); | 106 | std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE); |
| 98 | socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint); | 107 | socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint, {}, _ignored); |
| 99 | StartSend(timer.expiry()); | 108 | StartSend(timer.expiry()); |
| 100 | } | 109 | } |
| 101 | 110 | ||