Skip to content

Commit b18b284

Browse files
authored
Fix a bug when sending large messages using SSL (#42)
1 parent 7d6ca8e commit b18b284

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

trantor/net/inner/TcpConnectionImpl.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ void TcpConnectionImpl::sendFileInLoop(const BufferNodePtr &filePtr)
700700
if (n > 0)
701701
{
702702
auto nSend = writeInLoop(&buf[0], n);
703-
if (nSend > 0)
703+
if (nSend >= 0)
704704
{
705705
filePtr->_fileBytesToSend -= nSend;
706706
filePtr->_offset += nSend;
@@ -715,8 +715,6 @@ void TcpConnectionImpl::sendFileInLoop(const BufferNodePtr &filePtr)
715715
else if (nSend == n)
716716
continue;
717717
}
718-
if (nSend == 0)
719-
return;
720718
if (nSend < 0)
721719
{
722720
if (errno != EWOULDBLOCK)

trantor/net/ssl/SSLConnection.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void SSLConnection::doHandshaking()
239239
else
240240
{
241241
// ERR_print_errors(err);
242-
LOG_DEBUG << "SSL handshake err: " << err;
242+
LOG_TRACE << "SSL handshake err: " << err;
243243
_ioChannelPtr->disableReading();
244244
_status = SSLStatus::DisConnected;
245245
forceClose();
@@ -263,11 +263,15 @@ ssize_t SSLConnection::writeInLoop(const char *buffer, size_t length)
263263

264264
// send directly
265265
auto sendLen = SSL_write(_sslPtr->get(), buffer, length);
266-
int sslerr = SSL_get_error(_sslPtr->get(), sendLen);
267-
if (sendLen < 0 && sslerr != SSL_ERROR_WANT_WRITE)
266+
if (sendLen <= 0)
268267
{
269-
LOG_ERROR << "ssl write error:" << sslerr;
270-
return -1;
268+
int sslerr = SSL_get_error(_sslPtr->get(), sendLen);
269+
if (sslerr != SSL_ERROR_WANT_WRITE && sslerr != SSL_ERROR_WANT_READ)
270+
{
271+
LOG_ERROR << "ssl write error:" << sslerr;
272+
return -1;
273+
}
274+
return 0;
271275
}
272276
return sendLen;
273277
}

0 commit comments

Comments
 (0)