Skip to content

Commit 9d1d6db

Browse files
authored
Merge pull request #25 from an-tao/dev
Remove the temporary buffer in the SSLConnection class
2 parents ca966c8 + c63b564 commit 9d1d6db

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

trantor/net/ssl/SSLConnection.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ void SSLConnection::readCallback()
6060
else if (_status == SSLStatus::Connected)
6161
{
6262
int rd;
63-
char buf[4096];
6463
bool newDataFlag = false;
64+
size_t readLength;
6565
do
6666
{
67-
68-
rd = SSL_read(_sslPtr.get(), buf, sizeof(buf));
67+
_readBuffer.ensureWritableBytes(1024);
68+
readLength = _readBuffer.writableBytes();
69+
rd = SSL_read(_sslPtr.get(), _readBuffer.beginWrite(), readLength);
6970
LOG_TRACE << "ssl read:" << rd << " bytes";
7071
int sslerr = SSL_get_error(_sslPtr.get(), rd);
7172
if (rd <= 0 && sslerr != SSL_ERROR_WANT_READ)
@@ -77,11 +78,10 @@ void SSLConnection::readCallback()
7778
}
7879
if (rd > 0)
7980
{
80-
_readBuffer.append(buf, rd);
81+
_readBuffer.hasWritten(rd);
8182
newDataFlag = true;
8283
}
83-
84-
} while (rd == sizeof(buf));
84+
} while ((size_t)rd == readLength);
8585
if (newDataFlag)
8686
{
8787
//eval callback function;
@@ -131,7 +131,7 @@ void SSLConnection::doHandshaking()
131131
_ioChannelPtr->disableWriting();
132132
}
133133
else
134-
{ //错误
134+
{
135135
//ERR_print_errors(err);
136136
LOG_FATAL << "SSL handshake err";
137137
_ioChannelPtr->disableReading();

0 commit comments

Comments
 (0)