Skip to content

Commit 16e2265

Browse files
authored
Fix OpenSSL: read can be incomplete (#288)
1 parent d9de280 commit 16e2265

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

trantor/net/inner/tlsprovider/OpenSSLProvider.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,11 @@ struct OpenSSLProvider : public TLSProvider, public NonCopyable
714714
{
715715
constexpr size_t maxSingleRead = 128 * 1024;
716716
constexpr size_t maxWritibleBytes = (std::numeric_limits<int>::max)();
717-
auto inBio = SSL_get_rbio(ssl_);
718717
while (true)
719718
{
720-
auto pending = BIO_pending(inBio);
721-
if (pending <= 0)
722-
break;
719+
auto pending = BIO_pending(rbio_);
723720
// horrible syntax, because MSVC
721+
pending = (std::max)(1024, pending);
724722
recvBuffer_.ensureWritableBytes(
725723
(std::min)(maxSingleRead, (size_t)pending));
726724
// clamp to int, because that's what SSL_read accepts
@@ -734,7 +732,7 @@ struct OpenSSLProvider : public TLSProvider, public NonCopyable
734732
conn_->shutdown();
735733
return;
736734
}
737-
if (n > 0)
735+
else if (n > 0)
738736
{
739737
recvBuffer_.hasWritten(n);
740738
LOG_TRACE << "Received " << n << " bytes from SSL";

0 commit comments

Comments
 (0)