fix: handle plain HTTP on sslWriteAll

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