BugID:21900441:[hal tls]fix https read 0 length on platform linuxhost issue
@@ -781,9 +781,11 @@ static int _network_ssl_read(TLSDataParams_t *pTlsData, char *buffer, int len,
uint32_t readLen = 0;
static int net_status = 0;
int ret = -1;
- // char err_str[33] = {0};
+ uint32_t cur_time = HAL_UptimeMs();
+ uint32_t expire_time = cur_time + timeout_ms;
mbedtls_ssl_conf_read_timeout(&(pTlsData->conf), timeout_ms);
+
while (readLen < len) {
ret = mbedtls_ssl_read(&(pTlsData->ssl),
(unsigned char *)(buffer + readLen),
@@ -807,6 +809,16 @@ static int _network_ssl_read(TLSDataParams_t *pTlsData, char *buffer, int len,
platform_err("ssl recv error: code = %d", ret);
net_status = -2; /* connection is closed */
break;
+#ifdef CSP_LINUXHOST
+ } else if (MBEDTLS_ERR_SSL_WANT_READ == ret && errno == EINTR) {
+ cur_time = HAL_UptimeMs();
+ if ((cur_time - expire_time) < (UINT32_MAX / 2)) {
+ return readLen;
+ }
+ HAL_SleepMs(10);
+ continue;
+
+#endif
} else if ((MBEDTLS_ERR_SSL_TIMEOUT == ret) ||
(MBEDTLS_ERR_SSL_CONN_EOF == ret) ||
(MBEDTLS_ERR_SSL_SESSION_TICKET_EXPIRED == ret) ||
@@ -820,11 +832,6 @@ static int _network_ssl_read(TLSDataParams_t *pTlsData, char *buffer, int len,
else {
// mbedtls_strerror(ret, err_str, sizeof(err_str));
-#ifdef CSP_LINUXHOST
- if (MBEDTLS_ERR_SSL_WANT_READ == ret && errno == EINTR) {
- continue;
- }
-#endif
platform_err("ssl recv error: code = %d", ret);
#ifdef FEATURE_UND_SUPPORT
und_update_statis(UND_STATIS_NETWORK_EXCEPTION_IDX,
