From 67d518544b13a482013e21a149ea3b895804a74b Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Mon, 1 Aug 2022 15:51:40 +0200 Subject: [PATCH] EmbedReceiveFrom: fix when using a TCP socket - recvfrom() returns 0 on a closed TCP socket - TCP sockets set WOLFSSL_CBIO_ERR_ISR on a timeout --- src/wolfio.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/wolfio.c b/src/wolfio.c index 7a958d0ab..20a231ab9 100644 --- a/src/wolfio.c +++ b/src/wolfio.c @@ -481,6 +481,20 @@ int EmbedReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx) } return recvd; } + else if (recvd == 0) { + int type; + XSOCKLENT length = sizeof(int); /* optvalue 'type' is of size int */ + + if (getsockopt(sd, SOL_SOCKET, SO_TYPE, &type, &length) == 0 && + type != SOCK_DGRAM) { + /* Closed TCP connection */ + recvd = WOLFSSL_CBIO_ERR_CONN_CLOSE; + } + else { + WOLFSSL_MSG("Ignoring 0-length datagram"); + } + return recvd; + } else if (dtlsCtx->connected) { /* Nothing to do */ }