From f477b524bb2ebcacab705fca036d555cfa8f8e8d Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 24 Jan 2015 10:11:34 +0100 Subject: WebAdmin uses the new cNetwork API. --- src/HTTPServer/SslHTTPConnection.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'src/HTTPServer/SslHTTPConnection.cpp') 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(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(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: -- cgit v1.2.3