Fix TCP with Timeout

1. Take out DTLS support from EmbedReceive(). DTLS uses EmbedReceiveFrom().
2. Modify EmbedReceive() to return TIMEOUT if the session is set to blocking mode.
This commit is contained in:
John Safranek 2018-05-17 15:53:38 -07:00
parent 8ff328cb39
commit d8c33c5551
1 changed files with 1 additions and 22 deletions

View File

@ -194,34 +194,13 @@ int EmbedReceive(WOLFSSL *ssl, char *buf, int sz, void *ctx)
int sd = *(int*)ctx;
int recvd;
#ifdef WOLFSSL_DTLS
{
int dtls_timeout = wolfSSL_dtls_get_current_timeout(ssl);
if (wolfSSL_dtls(ssl)
&& !wolfSSL_get_using_nonblock(ssl)
&& dtls_timeout != 0) {
#ifdef USE_WINDOWS_API
DWORD timeout = dtls_timeout * 1000;
#else
struct timeval timeout;
XMEMSET(&timeout, 0, sizeof(timeout));
timeout.tv_sec = dtls_timeout;
#endif
if (setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout,
sizeof(timeout)) != 0) {
WOLFSSL_MSG("setsockopt rcvtimeo failed");
}
}
}
#endif
recvd = wolfIO_Recv(sd, buf, sz, ssl->rflags);
if (recvd < 0) {
int err = wolfSSL_LastError();
WOLFSSL_MSG("Embed Receive error");
if (err == SOCKET_EWOULDBLOCK || err == SOCKET_EAGAIN) {
if (!wolfSSL_dtls(ssl) || wolfSSL_get_using_nonblock(ssl)) {
if (wolfSSL_get_using_nonblock(ssl)) {
WOLFSSL_MSG("\tWould block");
return WOLFSSL_CBIO_ERR_WANT_READ;
}