From ea171a651cbcb2a3862e216b74c3088c6003ac13 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 18 Aug 2017 14:27:36 +1000 Subject: [PATCH] https example: Use correct pattern around mbedtls_ssl_write() mbedtls_ssl_write() will always write the request here in one go, but it's good to have correct patterns in examples. --- .../main/https_request_example_main.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/protocols/https_request/main/https_request_example_main.c b/examples/protocols/https_request/main/https_request_example_main.c index c12f7c18d4..a6cac56ca9 100644 --- a/examples/protocols/https_request/main/https_request_example_main.c +++ b/examples/protocols/https_request/main/https_request_example_main.c @@ -258,17 +258,20 @@ static void https_get_task(void *pvParameters) ESP_LOGI(TAG, "Writing HTTP request..."); - while((ret = mbedtls_ssl_write(&ssl, (const unsigned char *)REQUEST, strlen(REQUEST))) <= 0) - { - if(ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE) - { + size_t written_bytes = 0; + do { + ret = mbedtls_ssl_write(&ssl, + (const unsigned char *)REQUEST + written_bytes, + strlen(REQUEST) - written_bytes); + if (ret >= 0) { + ESP_LOGI(TAG, "%d bytes written", ret); + written_bytes += ret; + } else if (ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret != MBEDTLS_ERR_SSL_WANT_READ) { ESP_LOGE(TAG, "mbedtls_ssl_write returned -0x%x", -ret); goto exit; } - } + } while(written_bytes < strlen(REQUEST)); - len = ret; - ESP_LOGI(TAG, "%d bytes written", len); ESP_LOGI(TAG, "Reading HTTP response..."); do