idevice_error_t idevice_connection_receive_timeout(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout) { if (!connection || (connection->ssl_data && !connection->ssl_data->session)) { return IDEVICE_E_INVALID_ARG; } if (connection->ssl_data) { #ifdef HAVE_OPENSSL uint32_t received = 0; while (received < len) { int r = SSL_read(connection->ssl_data->session, (void*)((char*)(data+received)), (int)len-received); if (r > 0) { received += r; } else { break; } } debug_info("SSL_read %d, received %d,content:%s", len, received, data); #else ssize_t received = gnutls_record_recv(connection->ssl_data->session, (void*)data, (size_t)len); #endif if (received > 0) { *recv_bytes = received; return IDEVICE_E_SUCCESS; } *recv_bytes = 0; return IDEVICE_E_SSL_ERROR; } return internal_connection_receive_timeout(connection, data, len, recv_bytes, timeout); }
/** * Receive data from a device via the given connection. * This function will return after the given timeout even if no data has been * received. * * @param connection The connection to receive data from. * @param data Buffer that will be filled with the received data. * This buffer has to be large enough to hold len bytes. * @param len Buffer size or number of bytes to receive. * @param recv_bytes Number of bytes actually received. * @param timeout Timeout in milliseconds after which this function should * return even if no data has been received. * * @return IDEVICE_E_SUCCESS if ok, otherwise an error code. */ idevice_error_t idevice_connection_receive_timeout(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout) { if (!connection || (connection->ssl_data && !connection->ssl_data->session)) { return IDEVICE_E_INVALID_ARG; } if (connection->ssl_data) { ssize_t received = gnutls_record_recv(connection->ssl_data->session, (void*)data, (size_t)len); if (received > 0) { *recv_bytes = received; return IDEVICE_E_SUCCESS; } *recv_bytes = 0; return IDEVICE_E_SSL_ERROR; } return internal_connection_receive_timeout(connection, data, len, recv_bytes, timeout); }