From 67099fa41091ca57c6122da4a8b1edd98607120a Mon Sep 17 00:00:00 2001 From: VatamanuBogdan Date: Mon, 29 Jan 2024 15:58:03 +0200 Subject: [PATCH 1/2] fix: added extra exit code handling in "connect_to_port". --- IOSDeviceLib/IOSDeviceLib.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/IOSDeviceLib/IOSDeviceLib.cpp b/IOSDeviceLib/IOSDeviceLib.cpp index 452aaa9..b480611 100644 --- a/IOSDeviceLib/IOSDeviceLib.cpp +++ b/IOSDeviceLib/IOSDeviceLib.cpp @@ -1581,6 +1581,12 @@ void connect_to_port(std::string device_identifier, int port, int usb_result = USBMuxConnectByPort(connection_id, htons(port), &device_socket); + if (usb_result != 0) { + print_error("Failed to perform mux connect on device.", device_identifier, + method_id, usb_result); + return; + } + if (device_socket < 0) { print_error("USBMuxConnectByPort returned bad file descriptor", device_identifier, method_id, usb_result); From 835cf51b4e992cb2608960aec01f51a4b75dd70c Mon Sep 17 00:00:00 2001 From: VatamanuBogdan Date: Mon, 29 Jan 2024 16:08:27 +0200 Subject: [PATCH 2/2] fix: added extra traces for closed socket. --- IOSDeviceLib/IOSDeviceLib.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/IOSDeviceLib/IOSDeviceLib.cpp b/IOSDeviceLib/IOSDeviceLib.cpp index b480611..9d11c51 100644 --- a/IOSDeviceLib/IOSDeviceLib.cpp +++ b/IOSDeviceLib/IOSDeviceLib.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "CommonFunctions.h" #include "DevicectlHelper.h" @@ -1623,10 +1624,21 @@ void connect_to_port(std::string device_identifier, int port, // Proxy the messages from the client socket to the device socket // and from the device socket to the client socket. + auto on_device_socket_closed = [](SOCKET client_fd) { + trace("Device socket has been closed. Closing client socket."); + close_socket(client_fd); + }; + + auto on_client_socket_closed = [=](SOCKET d_fd) { + trace("Client socket has been closed. Closing associated device proxy " + "server."); + devices[device_identifier].kill_device_server(); + }; + proxy_socket_io( device_socket, client_socket, - [](SOCKET client_fd) { close_socket(client_fd); }, - [=](SOCKET d_fd) { devices[device_identifier].kill_device_server(); }); + std::move(on_device_socket_closed), + std::move(on_client_socket_closed)); } }