transport/pthread: fix some issues for component

1. transport_ssl: fix transport ssl blocking
2. pthread: fix the priority inheritance
This commit is contained in:
xutao
2020-09-21 15:18:36 +08:00
parent b94eec73fa
commit 7669600253
3 changed files with 24 additions and 8 deletions

View File

@@ -156,17 +156,22 @@ static const char *HTTP_METHOD_MAPPING[] = {
static void *http_malloc(size_t size) static void *http_malloc(size_t size)
{ {
void *data = NULL; void *data = NULL;
#if CONFIG_SPIRAM_USE_MALLOC
data = heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); data = heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
#else
data = malloc(size);
#endif
return data; return data;
} }
static void *http_calloc(size_t nmemb, size_t size) static void *http_calloc(size_t nmemb, size_t size)
{ {
void *data = NULL; void *data = NULL;
data = heap_caps_malloc(nmemb * size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); #if CONFIG_SPIRAM_USE_MALLOC
if (data) { data = heap_caps_calloc(nmemb, size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
memset(data, 0, nmemb * size); #else
} data = calloc(nmemb, size);
#endif
return data; return data;
} }

View File

@@ -591,6 +591,14 @@ int pthread_mutex_destroy(pthread_mutex_t *mutex)
return EBUSY; return EBUSY;
} }
if (mux->type == PTHREAD_MUTEX_RECURSIVE) {
res = xSemaphoreGiveRecursive(mux->sem);
} else {
res = xSemaphoreGive(mux->sem);
}
if (res != pdTRUE) {
assert(false && "Failed to release mutex!");
}
vSemaphoreDelete(mux->sem); vSemaphoreDelete(mux->sem);
free(mux); free(mux);

View File

@@ -80,12 +80,17 @@ static int ssl_connect(esp_transport_handle_t t, const char *host, int port, int
static int ssl_poll_read(esp_transport_handle_t t, int timeout_ms) static int ssl_poll_read(esp_transport_handle_t t, int timeout_ms)
{ {
transport_ssl_t *ssl = esp_transport_get_context_data(t); transport_ssl_t *ssl = esp_transport_get_context_data(t);
int remain = 0;
fd_set readset; fd_set readset;
FD_ZERO(&readset); FD_ZERO(&readset);
FD_SET(ssl->tls->sockfd, &readset); FD_SET(ssl->tls->sockfd, &readset);
struct timeval timeout; struct timeval timeout;
esp_transport_utils_ms_to_timeval(timeout_ms, &timeout); esp_transport_utils_ms_to_timeval(timeout_ms, &timeout);
if ((remain = esp_tls_get_bytes_avail(ssl->tls)) > 0) {
ESP_LOGD(TAG, "remain data in cache, need to read again");
return remain;
}
return select(ssl->tls->sockfd + 1, &readset, NULL, NULL, &timeout); return select(ssl->tls->sockfd + 1, &readset, NULL, NULL, &timeout);
} }
@@ -121,10 +126,8 @@ static int ssl_read(esp_transport_handle_t t, char *buffer, int len, int timeout
int poll, ret; int poll, ret;
transport_ssl_t *ssl = esp_transport_get_context_data(t); transport_ssl_t *ssl = esp_transport_get_context_data(t);
if (esp_tls_get_bytes_avail(ssl->tls) <= 0) { if ((poll = esp_transport_poll_read(t, timeout_ms)) <= 0) {
if ((poll = esp_transport_poll_read(t, timeout_ms)) <= 0) { return poll;
return poll;
}
} }
ret = esp_tls_conn_read(ssl->tls, (unsigned char *)buffer, len); ret = esp_tls_conn_read(ssl->tls, (unsigned char *)buffer, len);
if (ret < 0) { if (ret < 0) {