mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 20:24:32 +02:00
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.
This commit is contained in:
committed by
Angus Gratton
parent
f4404ae220
commit
ea171a651c
@@ -258,17 +258,20 @@ static void https_get_task(void *pvParameters)
|
|||||||
|
|
||||||
ESP_LOGI(TAG, "Writing HTTP request...");
|
ESP_LOGI(TAG, "Writing HTTP request...");
|
||||||
|
|
||||||
while((ret = mbedtls_ssl_write(&ssl, (const unsigned char *)REQUEST, strlen(REQUEST))) <= 0)
|
size_t written_bytes = 0;
|
||||||
{
|
do {
|
||||||
if(ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE)
|
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);
|
ESP_LOGE(TAG, "mbedtls_ssl_write returned -0x%x", -ret);
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
} while(written_bytes < strlen(REQUEST));
|
||||||
|
|
||||||
len = ret;
|
|
||||||
ESP_LOGI(TAG, "%d bytes written", len);
|
|
||||||
ESP_LOGI(TAG, "Reading HTTP response...");
|
ESP_LOGI(TAG, "Reading HTTP response...");
|
||||||
|
|
||||||
do
|
do
|
||||||
|
Reference in New Issue
Block a user