Skip to content

Added error handling improvements in connect_to_port #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions IOSDeviceLib/IOSDeviceLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include <sys/stat.h>
#include <thread>
#include <utility>

#include "CommonFunctions.h"
#include "DevicectlHelper.h"
Expand Down Expand Up @@ -1581,6 +1582,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);
Expand Down Expand Up @@ -1617,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));
}
}

Expand Down