summaryrefslogtreecommitdiffstats
path: root/src/HTTPServer/SslHTTPConnection.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-01-24 10:11:34 +0100
committerMattes D <github@xoft.cz>2015-01-27 14:53:26 +0100
commitf477b524bb2ebcacab705fca036d555cfa8f8e8d (patch)
treed8fd13670eddbd2e02e9e15330e20e1ad1c964fa /src/HTTPServer/SslHTTPConnection.cpp
parentIniFile: Added common code to migrate ports. (diff)
downloadcuberite-f477b524bb2ebcacab705fca036d555cfa8f8e8d.tar
cuberite-f477b524bb2ebcacab705fca036d555cfa8f8e8d.tar.gz
cuberite-f477b524bb2ebcacab705fca036d555cfa8f8e8d.tar.bz2
cuberite-f477b524bb2ebcacab705fca036d555cfa8f8e8d.tar.lz
cuberite-f477b524bb2ebcacab705fca036d555cfa8f8e8d.tar.xz
cuberite-f477b524bb2ebcacab705fca036d555cfa8f8e8d.tar.zst
cuberite-f477b524bb2ebcacab705fca036d555cfa8f8e8d.zip
Diffstat (limited to '')
-rw-r--r--src/HTTPServer/SslHTTPConnection.cpp33
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: