Skip to content

Commit 3163325

Browse files
rluboskartben
authored andcommitted
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>
1 parent 0e52ec3 commit 3163325

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

subsys/net/lib/sockets/sockets_tls.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,13 +2141,15 @@ int ztls_connect_ctx(struct tls_context *ctx, const struct sockaddr *addr,
21412141
{
21422142
int ret;
21432143
int sock_flags;
2144+
bool is_non_block;
21442145

21452146
sock_flags = zsock_fcntl(ctx->sock, F_GETFL, 0);
21462147
if (sock_flags < 0) {
21472148
return -EIO;
21482149
}
21492150

2150-
if (sock_flags & O_NONBLOCK) {
2151+
is_non_block = sock_flags & O_NONBLOCK;
2152+
if (is_non_block) {
21512153
(void)zsock_fcntl(ctx->sock, F_SETFL,
21522154
sock_flags & ~O_NONBLOCK);
21532155
}
@@ -2157,7 +2159,7 @@ int ztls_connect_ctx(struct tls_context *ctx, const struct sockaddr *addr,
21572159
return ret;
21582160
}
21592161

2160-
if (sock_flags & O_NONBLOCK) {
2162+
if (is_non_block) {
21612163
(void)zsock_fcntl(ctx->sock, F_SETFL, sock_flags);
21622164
}
21632165

@@ -2188,6 +2190,10 @@ int ztls_connect_ctx(struct tls_context *ctx, const struct sockaddr *addr,
21882190
ret = tls_mbedtls_handshake(
21892191
ctx, K_MSEC(CONFIG_NET_SOCKETS_CONNECT_TIMEOUT));
21902192
if (ret < 0) {
2193+
if ((ret == -EAGAIN) && !is_non_block) {
2194+
ret = -ETIMEDOUT;
2195+
}
2196+
21912197
goto error;
21922198
}
21932199

0 commit comments

Comments
 (0)