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:
parent
0e52ec34c3
commit
3163325e01
1 changed files with 8 additions and 2 deletions
|
@ -2141,13 +2141,15 @@ int ztls_connect_ctx(struct tls_context *ctx, const struct sockaddr *addr,
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
int sock_flags;
|
int sock_flags;
|
||||||
|
bool is_non_block;
|
||||||
|
|
||||||
sock_flags = zsock_fcntl(ctx->sock, F_GETFL, 0);
|
sock_flags = zsock_fcntl(ctx->sock, F_GETFL, 0);
|
||||||
if (sock_flags < 0) {
|
if (sock_flags < 0) {
|
||||||
return -EIO;
|
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,
|
(void)zsock_fcntl(ctx->sock, F_SETFL,
|
||||||
sock_flags & ~O_NONBLOCK);
|
sock_flags & ~O_NONBLOCK);
|
||||||
}
|
}
|
||||||
|
@ -2157,7 +2159,7 @@ int ztls_connect_ctx(struct tls_context *ctx, const struct sockaddr *addr,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sock_flags & O_NONBLOCK) {
|
if (is_non_block) {
|
||||||
(void)zsock_fcntl(ctx->sock, F_SETFL, sock_flags);
|
(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(
|
ret = tls_mbedtls_handshake(
|
||||||
ctx, K_MSEC(CONFIG_NET_SOCKETS_CONNECT_TIMEOUT));
|
ctx, K_MSEC(CONFIG_NET_SOCKETS_CONNECT_TIMEOUT));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
if ((ret == -EAGAIN) && !is_non_block) {
|
||||||
|
ret = -ETIMEDOUT;
|
||||||
|
}
|
||||||
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue