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:
parent
8ff328cb39
commit
d8c33c5551
23
src/wolfio.c
23
src/wolfio.c
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user