diff options
author | Nikias Bassen | 2019-07-19 00:06:38 +0700 |
---|---|---|
committer | Nikias Bassen | 2019-07-19 01:11:09 +0700 |
commit | f52584e7310ad9af414cdd22cbfad81d53417c22 (patch) | |
tree | ae4488955b67b676ca5735d622083746c339ce96 /src | |
parent | 2332655423c1616d8e37ece7f33e98be0e218504 (diff) | |
download | libimobiledevice-f52584e7310ad9af414cdd22cbfad81d53417c22.tar.gz libimobiledevice-f52584e7310ad9af414cdd22cbfad81d53417c22.tar.bz2 |
OpenSSL: Use SSL_pending() to determine if we want a select() before SSL_read()
In order to obey the timeout in idevice_connection_receive_timeout(), we are
using select() via socket_check_fd(). However, the SSL bio might have buffered
more bytes than actually requested upon a call to SSL_read(), so in the next
call to idevice_connection_receive_timeout() a select() would not find the fd
being ready to read, and make it fail with an error, after the specified
timeout is reached.
With the help of SSL_pending() we can now skip calling select() so that
SSL_read() will directly be called again.
Diffstat (limited to 'src')
-rw-r--r-- | src/idevice.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/idevice.c b/src/idevice.c index 02d34cc..794af8b 100644 --- a/src/idevice.c +++ b/src/idevice.c @@ -453,19 +453,24 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_receive_timeout(idevice_ if (connection->ssl_data) { uint32_t received = 0; + int do_select = 1; while (received < len) { - - int conn_error = socket_check_fd((int)(long)connection->data, FDM_READ, timeout); - idevice_error_t error = socket_recv_to_idevice_error(conn_error, len, received); - - switch (error) { - case IDEVICE_E_SUCCESS: - break; - case IDEVICE_E_UNKNOWN_ERROR: - debug_info("ERROR: socket_check_fd returned %d (%s)", conn_error, strerror(-conn_error)); - default: - return error; +#ifdef HAVE_OPENSSL + do_select = (SSL_pending(connection->ssl_data->session) == 0); +#endif + if (do_select) { + int conn_error = socket_check_fd((int)(long)connection->data, FDM_READ, timeout); + idevice_error_t error = socket_recv_to_idevice_error(conn_error, len, received); + + switch (error) { + case IDEVICE_E_SUCCESS: + break; + case IDEVICE_E_UNKNOWN_ERROR: + debug_info("ERROR: socket_check_fd returned %d (%s)", conn_error, strerror(-conn_error)); + default: + return error; + } } #ifdef HAVE_OPENSSL |