Skip to content

Commit 74f8c80

Browse files
authored
Merge pull request #541 from Azure/ewertons/fix_blob_upload_fail_mbedtls_1995
Fail to upload long Blob using mbedtls+compact(Issue #1995)
2 parents 3a7997a + e87f421 commit 74f8c80

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

adapters/httpapi_compact.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ HTTP_HANDLE HTTPAPI_CreateConnection(const char* hostName)
235235
tlsio_config.port = 443;
236236
tlsio_config.underlying_io_interface = NULL;
237237
tlsio_config.underlying_io_parameters = NULL;
238-
238+
tlsio_config.invoke_on_send_complete_callback_for_fragments = true;
239239
http_instance->xio_handle = xio_create(platform_get_default_tlsio(), (void*)&tlsio_config);
240240

241241
/*Codes_SRS_HTTPAPI_COMPACT_21_016: [ If the HTTPAPI_CreateConnection failed to create the connection, it shall return NULL as the handle. ]*/
@@ -1408,6 +1408,7 @@ HTTPAPI_RESULT HTTPAPI_SetOption(HTTP_HANDLE handle, const char* optionName, con
14081408
tlsio_config.port = 443;
14091409
tlsio_config.underlying_io_interface = http_proxy_io_get_interface_description();
14101410
tlsio_config.underlying_io_parameters = &proxy_config;
1411+
tlsio_config.invoke_on_send_complete_callback_for_fragments = true;
14111412

14121413
http_instance->xio_handle = xio_create(platform_get_default_tlsio(), (void*)&tlsio_config);
14131414

@@ -1567,4 +1568,3 @@ HTTPAPI_RESULT HTTPAPI_CloneOption(const char* optionName, const void* value, co
15671568
}
15681569
return result;
15691570
}
1570-

adapters/tlsio_mbedtls.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ typedef struct TLS_IO_INSTANCE_TAG
7272
mbedtls_ssl_session ssn;
7373
char *trusted_certificates;
7474

75+
bool invoke_on_send_complete_callback_for_fragments;
7576
char *hostname;
7677
mbedtls_x509_crt owncert;
7778
mbedtls_pk_context pKey;
@@ -373,12 +374,14 @@ static void on_send_complete(void* context, IO_SEND_RESULT send_result)
373374
if (tls_io_instance->send_complete_info.on_send_complete != NULL &&
374375
tls_io_instance->tlsio_state != TLSIO_STATE_CLOSING)
375376
{
376-
// trigger callback always on failure, otherwise call it on last fragment completion
377-
if (send_result != IO_SEND_OK || !tls_io_instance->send_complete_info.is_fragmented_req)
378-
{
377+
// trigger callback always on failure, otherwise call it on last fragment completion
378+
// In case of http communication (ie blob upload), the callback is called with each fragment
379+
if((tls_io_instance->invoke_on_send_complete_callback_for_fragments && tls_io_instance->send_complete_info.is_fragmented_req)||
380+
(send_result != IO_SEND_OK || !tls_io_instance->send_complete_info.is_fragmented_req))
381+
{
379382
void *ctx = tls_io_instance->send_complete_info.on_send_complete_callback_context;
380383
tls_io_instance->send_complete_info.on_send_complete(ctx, send_result);
381-
}
384+
}
382385
}
383386
}
384387
else
@@ -558,6 +561,7 @@ CONCRETE_IO_HANDLE tlsio_mbedtls_create(void *io_create_parameters)
558561
result->tls_status = TLS_STATE_NOT_INITIALIZED;
559562
mbedtls_init((void*)result);
560563
result->tlsio_state = TLSIO_STATE_NOT_OPEN;
564+
result->invoke_on_send_complete_callback_for_fragments = tls_io_config->invoke_on_send_complete_callback_for_fragments;
561565
}
562566
}
563567
}

inc/azure_c_shared_utility/tlsio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifndef TLSIO_H
55
#define TLSIO_H
66

7+
#include <stdbool.h>
78
#include "xio.h"
89

910
#ifdef __cplusplus
@@ -16,6 +17,7 @@ typedef struct TLSIO_CONFIG_TAG
1617
int port;
1718
const IO_INTERFACE_DESCRIPTION* underlying_io_interface;
1819
void* underlying_io_parameters;
20+
bool invoke_on_send_complete_callback_for_fragments;
1921
} TLSIO_CONFIG;
2022

2123
#ifdef __cplusplus

tests/tlsio_mbedtls_ut/tlsio_mbedtls_ut.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ BEGIN_TEST_SUITE(tlsio_mbedtls_ut)
880880
tls_io_config.port = TEST_CONNECTION_PORT;
881881
tls_io_config.underlying_io_interface = TEST_INTERFACE_DESC;
882882
tls_io_config.underlying_io_parameters = NULL;
883+
tls_io_config.invoke_on_send_complete_callback_for_fragments = false;
883884
CONCRETE_IO_HANDLE handle = tlsio_mbedtls_create(&tls_io_config);
884885
(void)tlsio_mbedtls_open(handle, on_io_open_complete, NULL, on_bytes_received, NULL, on_io_error, NULL);
885886
g_open_complete(g_open_complete_ctx, IO_OPEN_OK);
@@ -923,6 +924,7 @@ BEGIN_TEST_SUITE(tlsio_mbedtls_ut)
923924
tls_io_config.port = TEST_CONNECTION_PORT;
924925
tls_io_config.underlying_io_interface = TEST_INTERFACE_DESC;
925926
tls_io_config.underlying_io_parameters = NULL;
927+
tls_io_config.invoke_on_send_complete_callback_for_fragments = false;
926928
CONCRETE_IO_HANDLE handle = tlsio_mbedtls_create(&tls_io_config);
927929
(void)tlsio_mbedtls_open(handle, on_io_open_complete, NULL, on_bytes_received, NULL, on_io_error, NULL);
928930
g_open_complete(g_open_complete_ctx, IO_OPEN_OK);

0 commit comments

Comments
 (0)