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
pull/5427/head
Juliusz Sosinowicz 2022-08-01 15:51:40 +02:00
parent da422eb422
commit 67d518544b
1 changed files with 14 additions and 0 deletions

View File

@ -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 */
}