summaryrefslogtreecommitdiffstats
path: root/src/usbmux.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/usbmux.c')
-rw-r--r--src/usbmux.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/usbmux.c b/src/usbmux.c
index 22ce588..7d74b4b 100644
--- a/src/usbmux.c
+++ b/src/usbmux.c
@@ -143,7 +143,7 @@ iphone_error_t iphone_mux_new_client(iphone_device_t device, uint16_t src_port,
143 if (send_to_phone(device, (char *) new_connection->header, sizeof(usbmux_tcp_header)) >= 0) { 143 if (send_to_phone(device, (char *) new_connection->header, sizeof(usbmux_tcp_header)) >= 0) {
144 usbmux_tcp_header *response; 144 usbmux_tcp_header *response;
145 response = (usbmux_tcp_header *) malloc(sizeof(usbmux_tcp_header)); 145 response = (usbmux_tcp_header *) malloc(sizeof(usbmux_tcp_header));
146 bytes = recv_from_phone(device, (char *) response, sizeof(*response)); 146 bytes = recv_from_phone(device, (char *) response, sizeof(*response), 3500);
147 if (response->tcp_flags != 0x12) { 147 if (response->tcp_flags != 0x12) {
148 free(response); 148 free(response);
149 return IPHONE_E_UNKNOWN_ERROR; 149 return IPHONE_E_UNKNOWN_ERROR;
@@ -268,10 +268,13 @@ iphone_error_t iphone_mux_send(iphone_umux_client_t client, const char *data, ui
268 * @param connection The connection to receive data on. 268 * @param connection The connection to receive data on.
269 * @param data Where to put the data we receive. 269 * @param data Where to put the data we receive.
270 * @param datalen How much data to read. 270 * @param datalen How much data to read.
271 * @param recv_bytes Pointer to a uint32_t that will be set
272 * to the number of bytes received.
273 * @param timeout How many milliseconds to wait for data.
271 * 274 *
272 * @return How many bytes were read, or -1 if something bad happens. 275 * @return IPHONE_E_SUCCESS on success, or and error value.
273 */ 276 */
274iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t datalen, uint32_t * recv_bytes) 277iphone_error_t iphone_mux_recv_timeout(iphone_umux_client_t client, char *data, uint32_t datalen, uint32_t * recv_bytes, int timeout)
275{ 278{
276 279
277 if (!client || !data || datalen == 0 || !recv_bytes) 280 if (!client || !data || datalen == 0 || !recv_bytes)
@@ -323,7 +326,7 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t
323 buffer = (char *) malloc(sizeof(char) * 131072); // make sure we get enough ;) 326 buffer = (char *) malloc(sizeof(char) * 131072); // make sure we get enough ;)
324 327
325 // See #3. 328 // See #3.
326 bytes = recv_from_phone(client->phone, buffer, 131072); 329 bytes = recv_from_phone(client->phone, buffer, 131072, timeout);
327 if (bytes < 28) { 330 if (bytes < 28) {
328 free(buffer); 331 free(buffer);
329 log_debug_msg("mux_recv: Did not even get the header.\n"); 332 log_debug_msg("mux_recv: Did not even get the header.\n");
@@ -385,3 +388,23 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t
385 log_debug_msg("mux_recv: Heisenbug: bytes and datalen not matching up\n"); 388 log_debug_msg("mux_recv: Heisenbug: bytes and datalen not matching up\n");
386 return IPHONE_E_UNKNOWN_ERROR; 389 return IPHONE_E_UNKNOWN_ERROR;
387} 390}
391
392/**
393 * This function is just like 'iphone_mux_recv_timeout' but you do not need
394 * to specify a timeout. It simply calls iphone_mux_recv_timeout with a
395 * timeout value of 3500 milliseconds.
396 *
397 * @param connection The connection to receive data on.
398 * @param data Where to put the data we receive.
399 * @param datalen How much data to read.
400 * @param recv_bytes Pointer to a uint32_t that will be set
401 * to the number of bytes received.
402 *
403 * @return The return value of iphone_mux_recv_timeout.
404 *
405 * @see iphone_mux_recv_timeout
406 */
407iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t datalen, uint32_t * recv_bytes)
408{
409 return iphone_mux_recv_timeout(client, data, datalen, recv_bytes, 3500);
410}