From 397961eccdcf6aefd2733a615dd5d8870f440889 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 18 May 2020 20:14:20 +0200 Subject: idevice_connection_send: Make sure send works with non-blocking sockets --- src/idevice.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/idevice.c b/src/idevice.c index 418ee86..7b3625e 100644 --- a/src/idevice.c +++ b/src/idevice.c @@ -565,8 +565,24 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_send(idevice_connection_ } *sent_bytes = sent; return IDEVICE_E_SUCCESS; + } else { + uint32_t sent = 0; + while (sent < len) { + uint32_t bytes = 0; + int s = internal_connection_send(connection, data+sent, len-sent, &bytes); + if (s < 0) { + break; + } + sent += bytes; + } + debug_info("internal_connection_send %d, sent %d", len, sent); + if (sent < len) { + *sent_bytes = 0; + return IDEVICE_E_NOT_ENOUGH_DATA; + } + *sent_bytes = sent; + return IDEVICE_E_SUCCESS; } - return internal_connection_send(connection, data, len, sent_bytes); } static idevice_error_t socket_recv_to_idevice_error(int conn_error, uint32_t len, uint32_t received) -- cgit v1.1-32-gdbae