Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ixwebsocket/IXNetSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
#undef EINPROGRESS
#undef EBADF
#undef EINVAL
#undef ECONNRESET

// map to WSA error codes
#define EWOULDBLOCK WSAEWOULDBLOCK
#define EAGAIN WSATRY_AGAIN
#define EINPROGRESS WSAEINPROGRESS
#define EBADF WSAEBADF
#define EINVAL WSAEINVAL
#define ECONNRESET WSAECONNRESET

// Define our own poll on Windows, as a wrapper on top of select
typedef unsigned long int nfds_t;
Expand Down
11 changes: 11 additions & 0 deletions ixwebsocket/IXSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,17 @@ namespace ix
return err;
}

void Socket::setErrno(int err)
{
#ifdef _WIN32
// getErrno() reads WSAGetLastError() on Windows, the CRT errno is
// invisible to it
WSASetLastError(err);
#else
errno = err;
#endif
}

bool Socket::isWaitNeeded()
{
int err = getErrno();
Expand Down
1 change: 1 addition & 0 deletions ixwebsocket/IXSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace ix
const CancellationRequest& isCancellationRequested);

static int getErrno();
static void setErrno(int err);
static bool isWaitNeeded();
static void closeSocket(socket_t fd);

Expand Down
8 changes: 4 additions & 4 deletions ixwebsocket/IXSocketAppleSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,13 @@ namespace ix
if (status == errSSLClosedGraceful || status == errSSLClosedNoNotify ||
status == errSSLClosedAbort)
{
errno = ECONNRESET;
Socket::setErrno(ECONNRESET);
return -1;
}

if (status == errSSLWouldBlock)
{
errno = EWOULDBLOCK;
Socket::setErrno(EWOULDBLOCK);
return -1;
}
}
Expand All @@ -297,13 +297,13 @@ namespace ix
if (status == errSSLClosedGraceful || status == errSSLClosedNoNotify ||
status == errSSLClosedAbort)
{
errno = ECONNRESET;
Socket::setErrno(ECONNRESET);
return -1;
}

if (status == errSSLWouldBlock)
{
errno = EWOULDBLOCK;
Socket::setErrno(EWOULDBLOCK);
return -1;
}
}
Expand Down
22 changes: 19 additions & 3 deletions ixwebsocket/IXSocketMbedTLS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ namespace ix
}
else if (res == MBEDTLS_ERR_SSL_WANT_READ || res == MBEDTLS_ERR_SSL_WANT_WRITE)
{
errno = EWOULDBLOCK;
Socket::setErrno(EWOULDBLOCK);
return -1;
}
else
Expand All @@ -369,14 +369,30 @@ namespace ix
return res;
}

// TLS 1.3 (mbedtls 3.6+): the server can send post-handshake messages
// (NewSessionTicket, early data) which surface as non-fatal "read again"
// return codes. Retry the read instead of treating them as errors.
#if defined(MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET)
if (res == MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET)
{
continue;
}
#endif
#if defined(MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA)
if (res == MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA)
{
continue;
}
#endif

if (res == 0)
{
errno = ECONNRESET;
Socket::setErrno(ECONNRESET);
}

if (res == MBEDTLS_ERR_SSL_WANT_READ || res == MBEDTLS_ERR_SSL_WANT_WRITE)
{
errno = EWOULDBLOCK;
Socket::setErrno(EWOULDBLOCK);
}
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions ixwebsocket/IXSocketOpenSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ namespace ix
}
else if (reason == SSL_ERROR_WANT_READ || reason == SSL_ERROR_WANT_WRITE)
{
errno = EWOULDBLOCK;
Socket::setErrno(EWOULDBLOCK);
return -1;
}
else
Expand Down Expand Up @@ -869,7 +869,7 @@ namespace ix

if (reason == SSL_ERROR_WANT_READ || reason == SSL_ERROR_WANT_WRITE)
{
errno = EWOULDBLOCK;
Socket::setErrno(EWOULDBLOCK);
}
return -1;
}
Expand Down
Loading