summaryrefslogtreecommitdiffstats
path: root/src/HTTPServer/SslHTTPConnection.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/HTTPServer/SslHTTPConnection.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/HTTPServer/SslHTTPConnection.cpp b/src/HTTPServer/SslHTTPConnection.cpp
index d237089d9..f8dea0731 100644
--- a/src/HTTPServer/SslHTTPConnection.cpp
+++ b/src/HTTPServer/SslHTTPConnection.cpp
@@ -25,14 +25,17 @@ cSslHTTPConnection::cSslHTTPConnection(cHTTPServer & a_HTTPServer, const cX509Ce
-bool cSslHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
+cSslHTTPConnection::~cSslHTTPConnection()
+{
+ m_Ssl.NotifyClose();
+}
+
+
+
+
+
+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 +55,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 +75,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 +97,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: