diff options
author | Howaner <franzi.moos@googlemail.com> | 2015-02-06 21:52:14 +0100 |
---|---|---|
committer | Howaner <franzi.moos@googlemail.com> | 2015-02-06 21:52:14 +0100 |
commit | 2c7925f0adc17d7680ff9791832ab2c349c2301f (patch) | |
tree | ef6233b0d9dece6f7520996f2a4d850470e2c2d3 /src/HTTPServer/SslHTTPConnection.cpp | |
parent | Readded old DistributeStackToAreas() comment. (diff) | |
parent | Switched LuaState to use sizeof... (diff) | |
download | cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.tar cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.tar.gz cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.tar.bz2 cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.tar.lz cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.tar.xz cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.tar.zst cuberite-2c7925f0adc17d7680ff9791832ab2c349c2301f.zip |
Diffstat (limited to 'src/HTTPServer/SslHTTPConnection.cpp')
-rw-r--r-- | src/HTTPServer/SslHTTPConnection.cpp | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/HTTPServer/SslHTTPConnection.cpp b/src/HTTPServer/SslHTTPConnection.cpp index d237089d9..f09daac8f 100644 --- a/src/HTTPServer/SslHTTPConnection.cpp +++ b/src/HTTPServer/SslHTTPConnection.cpp @@ -25,14 +25,8 @@ cSslHTTPConnection::cSslHTTPConnection(cHTTPServer & a_HTTPServer, const cX509Ce -bool cSslHTTPConnection::DataReceived(const char * a_Data, size_t a_Size) +void cSslHTTPConnection::OnReceivedData(const char * a_Data, size_t a_Size) { - // If there is outgoing data in the queue, notify the server that it should write it out: - if (!m_OutgoingData.empty()) - { - m_HTTPServer.NotifyConnectionWrite(*this); - } - // Process the received data: const char * Data = a_Data; size_t Size = a_Size; @@ -52,17 +46,18 @@ bool cSslHTTPConnection::DataReceived(const char * a_Data, size_t a_Size) int NumRead = m_Ssl.ReadPlain(Buffer, sizeof(Buffer)); if (NumRead > 0) { - if (super::DataReceived(Buffer, (size_t)NumRead)) - { - // The socket has been closed, and the object is already deleted. Bail out. - return true; - } + super::OnReceivedData(Buffer, (size_t)NumRead); + } + else if (NumRead == POLARSSL_ERR_NET_WANT_READ) + { + // SSL requires us to send data to peer first, do so by "sending" empty data: + SendData(nullptr, 0); } // If both failed, bail out: if ((BytesWritten == 0) && (NumRead <= 0)) { - return false; + return; } } } @@ -71,18 +66,20 @@ bool cSslHTTPConnection::DataReceived(const char * a_Data, size_t a_Size) -void cSslHTTPConnection::GetOutgoingData(AString & a_Data) +void cSslHTTPConnection::SendData(const void * a_Data, size_t a_Size) { + const char * OutgoingData = reinterpret_cast<const char *>(a_Data); + size_t pos = 0; for (;;) { // Write as many bytes from our buffer to SSL's encryption as possible: int NumWritten = 0; - if (!m_OutgoingData.empty()) + if (pos < a_Size) { - NumWritten = m_Ssl.WritePlain(m_OutgoingData.data(), m_OutgoingData.size()); + NumWritten = m_Ssl.WritePlain(OutgoingData + pos, a_Size - pos); if (NumWritten > 0) { - m_OutgoingData.erase(0, (size_t)NumWritten); + pos += static_cast<size_t>(NumWritten); } } @@ -91,7 +88,7 @@ void cSslHTTPConnection::GetOutgoingData(AString & a_Data) size_t NumBytes = m_Ssl.ReadOutgoing(Buffer, sizeof(Buffer)); if (NumBytes > 0) { - a_Data.append(Buffer, NumBytes); + m_Link->Send(Buffer, NumBytes); } // If both failed, bail out: |