Skip to content

Commit f4a18e4

Browse files
rluboscarlescufi
authored andcommitted
net: sockets: tls: Fix ZSOCK_POLLHUP detection
The previous approach to detect if the underlying transport was closed (by checking the return value of `mbedtls_ssl_read()` was not right, since the function call does not request any data - therefore 0 as a return value is perfectly fine. Instead, rely on the underlying transport ZSOCK_POLLHUP event - if it reports that the connection ended, forward the event to the application. Signed-off-by: Robert Lubos <[email protected]>
1 parent f875162 commit f4a18e4

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

subsys/net/lib/sockets/sockets_tls.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,8 +2176,6 @@ static int ztls_socket_data_check(struct tls_context *ctx)
21762176

21772177
/* Treat any other error as fatal. */
21782178
return -EIO;
2179-
} else if (ret == 0 && ctx->type == SOCK_STREAM) {
2180-
return -ENOTCONN;
21812179
}
21822180

21832181
return mbedtls_ssl_get_bytes_avail(&ctx->ssl);
@@ -2206,7 +2204,7 @@ static int ztls_poll_update_pollin(int fd, struct tls_context *ctx,
22062204
}
22072205

22082206
ret = ztls_socket_data_check(ctx);
2209-
if (ret == -ENOTCONN) {
2207+
if (ret == -ENOTCONN || (pfd->revents & ZSOCK_POLLHUP)) {
22102208
/* Datagram does not return 0 on consecutive recv, but an error
22112209
* code, hence clear POLLIN.
22122210
*/

0 commit comments

Comments
 (0)