mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-01 19:54:32 +02:00
fix(transport): Fix a bug of the connection whether be active or not.
This commit is contained in:
@@ -80,24 +80,48 @@ 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 ret = -1;
|
||||||
fd_set readset;
|
fd_set readset;
|
||||||
|
fd_set errset;
|
||||||
FD_ZERO(&readset);
|
FD_ZERO(&readset);
|
||||||
|
FD_ZERO(&errset);
|
||||||
FD_SET(ssl->tls->sockfd, &readset);
|
FD_SET(ssl->tls->sockfd, &readset);
|
||||||
|
FD_SET(ssl->tls->sockfd, &errset);
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
esp_transport_utils_ms_to_timeval(timeout_ms, &timeout);
|
esp_transport_utils_ms_to_timeval(timeout_ms, &timeout);
|
||||||
|
|
||||||
return select(ssl->tls->sockfd + 1, &readset, NULL, NULL, &timeout);
|
ret = select(ssl->tls->sockfd + 1, &readset, NULL, &errset, &timeout);
|
||||||
|
if (ret > 0 && FD_ISSET(ssl->tls->sockfd, &errset)) {
|
||||||
|
int sock_errno = 0;
|
||||||
|
uint32_t optlen = sizeof(sock_errno);
|
||||||
|
getsockopt(ssl->tls->sockfd, SOL_SOCKET, SO_ERROR, &sock_errno, &optlen);
|
||||||
|
ESP_LOGE(TAG, "Poll read catch a error, errno = %s, fd = %d", strerror(sock_errno), ssl->tls->sockfd);
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ssl_poll_write(esp_transport_handle_t t, int timeout_ms)
|
static int ssl_poll_write(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 ret = -1;
|
||||||
fd_set writeset;
|
fd_set writeset;
|
||||||
|
fd_set errset;
|
||||||
FD_ZERO(&writeset);
|
FD_ZERO(&writeset);
|
||||||
|
FD_ZERO(&errset);
|
||||||
FD_SET(ssl->tls->sockfd, &writeset);
|
FD_SET(ssl->tls->sockfd, &writeset);
|
||||||
|
FD_SET(ssl->tls->sockfd, &errset);
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
esp_transport_utils_ms_to_timeval(timeout_ms, &timeout);
|
esp_transport_utils_ms_to_timeval(timeout_ms, &timeout);
|
||||||
return select(ssl->tls->sockfd + 1, NULL, &writeset, NULL, &timeout);
|
ret = select(ssl->tls->sockfd + 1, NULL, &writeset, &errset, &timeout);
|
||||||
|
if (ret > 0 && FD_ISSET(ssl->tls->sockfd, &errset)) {
|
||||||
|
int sock_errno = 0;
|
||||||
|
uint32_t optlen = sizeof(sock_errno);
|
||||||
|
getsockopt(ssl->tls->sockfd, SOL_SOCKET, SO_ERROR, &sock_errno, &optlen);
|
||||||
|
ESP_LOGE(TAG, "Poll write catch a error, errno = %s, fd = %d", strerror(sock_errno), ssl->tls->sockfd);
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ssl_write(esp_transport_handle_t t, const char *buffer, int len, int timeout_ms)
|
static int ssl_write(esp_transport_handle_t t, const char *buffer, int len, int timeout_ms)
|
||||||
|
@@ -115,23 +115,47 @@ static int tcp_read(esp_transport_handle_t t, char *buffer, int len, int timeout
|
|||||||
static int tcp_poll_read(esp_transport_handle_t t, int timeout_ms)
|
static int tcp_poll_read(esp_transport_handle_t t, int timeout_ms)
|
||||||
{
|
{
|
||||||
transport_tcp_t *tcp = esp_transport_get_context_data(t);
|
transport_tcp_t *tcp = esp_transport_get_context_data(t);
|
||||||
|
int ret = -1;
|
||||||
fd_set readset;
|
fd_set readset;
|
||||||
|
fd_set errset;
|
||||||
FD_ZERO(&readset);
|
FD_ZERO(&readset);
|
||||||
|
FD_ZERO(&errset);
|
||||||
FD_SET(tcp->sock, &readset);
|
FD_SET(tcp->sock, &readset);
|
||||||
|
FD_SET(tcp->sock, &errset);
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
esp_transport_utils_ms_to_timeval(timeout_ms, &timeout);
|
esp_transport_utils_ms_to_timeval(timeout_ms, &timeout);
|
||||||
return select(tcp->sock + 1, &readset, NULL, NULL, &timeout);
|
ret = select(tcp->sock + 1, &readset, NULL, &errset, &timeout);
|
||||||
|
if (ret > 0 && FD_ISSET(tcp->sock, &errset)) {
|
||||||
|
int sock_errno = 0;
|
||||||
|
uint32_t optlen = sizeof(sock_errno);
|
||||||
|
getsockopt(tcp->sock, SOL_SOCKET, SO_ERROR, &sock_errno, &optlen);
|
||||||
|
ESP_LOGE(TAG, "Poll read catch a error, errno = %s, fd = %d", strerror(sock_errno), tcp->sock);
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tcp_poll_write(esp_transport_handle_t t, int timeout_ms)
|
static int tcp_poll_write(esp_transport_handle_t t, int timeout_ms)
|
||||||
{
|
{
|
||||||
transport_tcp_t *tcp = esp_transport_get_context_data(t);
|
transport_tcp_t *tcp = esp_transport_get_context_data(t);
|
||||||
|
int ret = -1;
|
||||||
fd_set writeset;
|
fd_set writeset;
|
||||||
|
fd_set errset;
|
||||||
FD_ZERO(&writeset);
|
FD_ZERO(&writeset);
|
||||||
|
FD_ZERO(&errset);
|
||||||
FD_SET(tcp->sock, &writeset);
|
FD_SET(tcp->sock, &writeset);
|
||||||
|
FD_SET(tcp->sock, &errset);
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
esp_transport_utils_ms_to_timeval(timeout_ms, &timeout);
|
esp_transport_utils_ms_to_timeval(timeout_ms, &timeout);
|
||||||
return select(tcp->sock + 1, NULL, &writeset, NULL, &timeout);
|
ret = select(tcp->sock + 1, NULL, &writeset, &errset, &timeout);
|
||||||
|
if (ret > 0 && FD_ISSET(tcp->sock, &errset)) {
|
||||||
|
int sock_errno = 0;
|
||||||
|
uint32_t optlen = sizeof(sock_errno);
|
||||||
|
getsockopt(tcp->sock, SOL_SOCKET, SO_ERROR, &sock_errno, &optlen);
|
||||||
|
ESP_LOGE(TAG, "Poll write catch a error, errno = %s, fd = %d", strerror(sock_errno), tcp->sock);
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tcp_close(esp_transport_handle_t t)
|
static int tcp_close(esp_transport_handle_t t)
|
||||||
|
Reference in New Issue
Block a user