fix: handle plain HTTP on sslWriteAll

This commit is contained in:
2026-05-13 12:05:22 -03:00
parent 9d71fd2d20
commit f6207784ab
+26 -7
View File
@@ -108,26 +108,45 @@ bool sslWriteAll(WOLFSSL* ssl, const void* data, int len, SOCKET s)
int sent = 0;
while (sent < len)
{
int ret = wolfSSL_write(ssl, (const char*)data + sent, len - sent);
if (ret > 0)
int ret;
if (ssl)
{
ret = wolfSSL_write(ssl, (const char*)data + sent, len - sent);
if (ret <= 0)
{
sent += ret;
continue;
}
int err = wolfSSL_get_error(ssl, ret);
if (err == WOLFSSL_ERROR_WANT_READ || err == WOLFSSL_ERROR_WANT_WRITE)
{
fd_set fds;
FD_ZERO(&fds);
FD_SET(s, &fds);
struct timeval tv{0, 10000}; // 10ms wait
struct timeval tv{0, 10000};
select(0, (err == WOLFSSL_ERROR_WANT_READ) ? &fds : nullptr,
(err == WOLFSSL_ERROR_WANT_WRITE) ? &fds : nullptr, nullptr, &tv);
continue;
}
return false;
}
}
else
{
ret = ::send(s, (const char*)data + sent, len - sent, 0);
if (ret <= 0)
{
#ifdef _WIN32
if (ret < 0 && WSAGetLastError() == WSAEWOULDBLOCK)
#else
if (ret < 0 && (errno == EWOULDBLOCK || errno == EAGAIN))
#endif
{
std::this_thread::sleep_for(std::chrono::milliseconds(1));
continue;
}
return false;
}
}
sent += ret;
}
return true;
}