net: sockets: tls: Fix connect timeout error code

In case TLS connect timed out during the handshake, errno was set to
EAGAIN which is unexpected and confusing. Fix this and set the errno
to ETIMEDOUT instead.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2024-12-04 17:19:36 +01:00 committed by Benjamin Cabé
commit 3163325e01

View file

@ -2141,13 +2141,15 @@ int ztls_connect_ctx(struct tls_context *ctx, const struct sockaddr *addr,
{
int ret;
int sock_flags;
bool is_non_block;
sock_flags = zsock_fcntl(ctx->sock, F_GETFL, 0);
if (sock_flags < 0) {
return -EIO;
}
if (sock_flags & O_NONBLOCK) {
is_non_block = sock_flags & O_NONBLOCK;
if (is_non_block) {
(void)zsock_fcntl(ctx->sock, F_SETFL,
sock_flags & ~O_NONBLOCK);
}
@ -2157,7 +2159,7 @@ int ztls_connect_ctx(struct tls_context *ctx, const struct sockaddr *addr,
return ret;
}
if (sock_flags & O_NONBLOCK) {
if (is_non_block) {
(void)zsock_fcntl(ctx->sock, F_SETFL, sock_flags);
}
@ -2188,6 +2190,10 @@ int ztls_connect_ctx(struct tls_context *ctx, const struct sockaddr *addr,
ret = tls_mbedtls_handshake(
ctx, K_MSEC(CONFIG_NET_SOCKETS_CONNECT_TIMEOUT));
if (ret < 0) {
if ((ret == -EAGAIN) && !is_non_block) {
ret = -ETIMEDOUT;
}
goto error;
}