From 36cfb234d5f867a59f102ac2ffd71dc1c669cf46 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 16 Oct 2020 06:22:26 -0400 Subject: [PATCH 1/2] udp/client: Take std::function by const reference with TestCommunication() Avoids redundant copies. --- src/input_common/udp/client.cpp | 6 +++--- src/input_common/udp/client.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index bb109562c..e3dd8a4be 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -333,15 +333,15 @@ const std::array, 4>& Client::GetPadQueue() cons } void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, u32 client_id, - std::function success_callback, - std::function failure_callback) { + const std::function& success_callback, + const std::function& failure_callback) { std::thread([=] { Common::Event success_event; SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, [&](Response::PadData data) { success_event.Set(); }}; Socket socket{host, port, pad_index, client_id, std::move(callback)}; std::thread worker_thread{SocketLoop, &socket}; - bool result = success_event.WaitFor(std::chrono::seconds(8)); + const bool result = success_event.WaitFor(std::chrono::seconds(8)); socket.Stop(); worker_thread.join(); if (result) { diff --git a/src/input_common/udp/client.h b/src/input_common/udp/client.h index 2491a03a2..747e0c0a2 100644 --- a/src/input_common/udp/client.h +++ b/src/input_common/udp/client.h @@ -150,7 +150,7 @@ private: }; void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, u32 client_id, - std::function success_callback, - std::function failure_callback); + const std::function& success_callback, + const std::function& failure_callback); } // namespace InputCommon::CemuhookUDP From 30b1e71066b59304af452af65d73b6b8cbf76929 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 16 Oct 2020 06:23:48 -0400 Subject: [PATCH 2/2] udp/client: Make use of designated initializers in TestCommunication() Same behavior, but makes the callback list nicer to look at. --- src/input_common/udp/client.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index e3dd8a4be..7039d6fc3 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -337,8 +337,11 @@ void TestCommunication(const std::string& host, u16 port, std::size_t pad_index, const std::function& failure_callback) { std::thread([=] { Common::Event success_event; - SocketCallback callback{[](Response::Version version) {}, [](Response::PortInfo info) {}, - [&](Response::PadData data) { success_event.Set(); }}; + SocketCallback callback{ + .version = [](Response::Version) {}, + .port_info = [](Response::PortInfo) {}, + .pad_data = [&](Response::PadData) { success_event.Set(); }, + }; Socket socket{host, port, pad_index, client_id, std::move(callback)}; std::thread worker_thread{SocketLoop, &socket}; const bool result = success_event.WaitFor(std::chrono::seconds(8));