Azure IoT common library
Dependents: STM32F746_iothub_client_sample_mqtt f767zi_mqtt iothub_client_sample_amqp iothub_client_sample_http ... more
Diff: tlsio_wolfssl.c
- Revision:
- 47:e59b74c745bc
- Parent:
- 46:fde927ea2e72
- Child:
- 48:81866008bba4
--- a/tlsio_wolfssl.c Tue Jun 26 19:16:17 2018 -0700 +++ b/tlsio_wolfssl.c Thu Jul 12 18:10:56 2018 -0700 @@ -54,6 +54,7 @@ } TLS_IO_INSTANCE; STATIC_VAR_UNUSED const char* const OPTION_WOLFSSL_SET_DEVICE_ID = "SetDeviceId"; +static const size_t SOCKET_READ_LIMIT = 5; /*this function will clone an option given by name and value*/ static void* tlsio_wolfssl_CloneOption(const char* name, const void* value) @@ -225,8 +226,8 @@ int result = 0; unsigned char buffer[64]; - int rcv_bytes = 1; - while (rcv_bytes > 0) + int rcv_bytes = 0; + do { rcv_bytes = wolfSSL_read(tls_io_instance->ssl, buffer, sizeof(buffer)); if (rcv_bytes > 0) @@ -236,8 +237,7 @@ tls_io_instance->on_bytes_received(tls_io_instance->on_bytes_received_context, buffer, rcv_bytes); } } - } - + } while (rcv_bytes > 0); return result; } @@ -351,15 +351,17 @@ { TLS_IO_INSTANCE* tls_io_instance = (TLS_IO_INSTANCE*)context; unsigned char* new_socket_io_read_bytes; + size_t socket_reads = 0; AZURE_UNREFERENCED_PARAMETER(ssl); - while (tls_io_instance->socket_io_read_byte_count == 0) + while (tls_io_instance->socket_io_read_byte_count == 0 && socket_reads < SOCKET_READ_LIMIT) { xio_dowork(tls_io_instance->socket_io); if (tls_io_instance->tlsio_state != TLSIO_STATE_IN_HANDSHAKE) { break; } + socket_reads++; } result = tls_io_instance->socket_io_read_byte_count;