diff options
author | Nikias Bassen | 2019-01-18 20:43:47 +0100 |
---|---|---|
committer | Nikias Bassen | 2019-01-18 20:43:47 +0100 |
commit | c75605d862cd1c312494f6c715246febc26b2e05 (patch) | |
tree | 65310c287d9f996f79bb6b69ca47564b090e43a5 | |
parent | 9db5747cd823b1f59794f81560a4af22a031f5c9 (diff) | |
download | libusbmuxd-c75605d862cd1c312494f6c715246febc26b2e05.tar.gz libusbmuxd-c75605d862cd1c312494f6c715246febc26b2e05.tar.bz2 |
Return meaningful error codes from usbmuxd_connect()
-rw-r--r-- | include/usbmuxd.h | 3 | ||||
-rw-r--r-- | src/libusbmuxd.c | 18 |
2 files changed, 15 insertions, 6 deletions
diff --git a/include/usbmuxd.h b/include/usbmuxd.h index 0cb7cab..6d035a2 100644 --- a/include/usbmuxd.h +++ b/include/usbmuxd.h @@ -170,7 +170,8 @@ int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *device, enum usb * @param tcp_port TCP port number on device, in range 0-65535. * common values are 62078 for lockdown, and 22 for SSH. * - * @return socket file descriptor of the connection, or -1 on error + * @return socket file descriptor of the connection, or a negative errno + * value on error. */ int usbmuxd_connect(const uint32_t handle, const unsigned short tcp_port); diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c index 26d0465..537c351 100644 --- a/src/libusbmuxd.c +++ b/src/libusbmuxd.c @@ -1374,14 +1374,14 @@ USBMUXD_API int usbmuxd_connect(const uint32_t handle, const unsigned short port int sfd; int tag; int connected = 0; - uint32_t res = -1; + int result = EBADF; retry: sfd = connect_usbmuxd_socket(); if (sfd < 0) { - LIBUSBMUXD_DEBUG(1, "%s: Error: Connection to usbmuxd failed: %s\n", - __func__, strerror(errno)); - return sfd; + result = errno; + LIBUSBMUXD_DEBUG(1, "%s: Error: Connection to usbmuxd failed: %s\n", __func__, strerror(result)); + return -result; } tag = ++use_tag; @@ -1389,6 +1389,7 @@ retry: LIBUSBMUXD_DEBUG(1, "%s: Error sending connect message!\n", __func__); } else { // read ACK + uint32_t res = -1; LIBUSBMUXD_DEBUG(2, "%s: Reading connect result...\n", __func__); if (usbmuxd_get_result(sfd, tag, &res, NULL) == 1) { if (res == 0) { @@ -1401,6 +1402,13 @@ retry: goto retry; } LIBUSBMUXD_DEBUG(1, "%s: Connect failed, Error code=%d\n", __func__, res); + if (res == RESULT_CONNREFUSED) { + result = ECONNREFUSED; + } else if (res == RESULT_BADDEV) { + result = ENODEV; + } else { + result = EBADF; + } } } } @@ -1411,7 +1419,7 @@ retry: socket_close(sfd); - return -1; + return -result; } USBMUXD_API int usbmuxd_disconnect(int sfd) |