From 78fb3bc2401edb75edbd7fcb29a4c41e7c1907f2 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 14 Sep 2021 13:47:27 +0900 Subject: [PATCH] webclient: handle EINTR in a few places --- netutils/webclient/webclient.c | 39 ++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/netutils/webclient/webclient.c b/netutils/webclient/webclient.c index bc5eb389c..570f62292 100644 --- a/netutils/webclient/webclient.c +++ b/netutils/webclient/webclient.c @@ -265,11 +265,17 @@ static ssize_t conn_send(struct webclient_context *ctx, struct conn_s *conn, { return ctx->tls_ops->send(ctx->tls_ctx, conn->tls_conn, buffer, len); } - else + + while (true) { ssize_t ret = send(conn->sockfd, buffer, len, 0); if (ret == -1) { + if (errno == EINTR) + { + continue; + } + if (errno == EAGAIN) { conn->flags |= CONN_WANT_WRITE; @@ -293,11 +299,17 @@ static ssize_t conn_recv(struct webclient_context *ctx, struct conn_s *conn, { return ctx->tls_ops->recv(ctx->tls_ctx, conn->tls_conn, buffer, len); } - else + + while (true) { ssize_t ret = recv(conn->sockfd, buffer, len, 0); if (ret == -1) { + if (errno == EINTR) + { + continue; + } + if (errno == EAGAIN) { conn->flags |= CONN_WANT_READ; @@ -1059,16 +1071,25 @@ int webclient_perform(FAR struct webclient_context *ctx) * arbitrary local port that is not in use. */ - ret = connect(conn->sockfd, server_address, - server_address_len); - if (ret == -1) + while (true) { - ret = -errno; - DEBUGASSERT(ret < 0); - if (ret == -EISCONN) + ret = connect(conn->sockfd, server_address, + server_address_len); + if (ret == -1) { - ret = 0; + ret = -errno; + DEBUGASSERT(ret < 0); + if (ret == -EINTR) + { + continue; + } + + if (ret == -EISCONN) + { + ret = 0; + } } + break; } }