apps: Fix the bug that setsockopt didn't check return value

Signed-off-by: weizihan <weizihan@xiaomi.com>
This commit is contained in:
weizihan 2022-05-06 15:46:04 +08:00 committed by Xiang Xiao
parent a9f6d66888
commit 9dd3055014

View File

@ -1417,10 +1417,27 @@ int webclient_perform(FAR struct webclient_context *ctx)
tv.tv_sec = ctx->timeout_sec;
tv.tv_usec = 0;
setsockopt(conn->sockfd, SOL_SOCKET, SO_RCVTIMEO,
(FAR const void *)&tv, sizeof(struct timeval));
setsockopt(conn->sockfd, SOL_SOCKET, SO_SNDTIMEO,
(FAR const void *)&tv, sizeof(struct timeval));
/* Check return value one by one */
ret = setsockopt(conn->sockfd, SOL_SOCKET, SO_RCVTIMEO,
(FAR const void *)&tv,
sizeof(struct timeval));
if (ret != 0)
{
ret = -errno;
nerr("ERROR: setsockopt failed: %d\n", ret);
goto errout_with_errno;
}
ret = setsockopt(conn->sockfd, SOL_SOCKET, SO_SNDTIMEO,
(FAR const void *)&tv,
sizeof(struct timeval));
if (ret != 0)
{
ret = -errno;
nerr("ERROR: setsockopt failed: %d\n", ret);
goto errout_with_errno;
}
}
}