summaryrefslogtreecommitdiffstats
path: root/src/HTTPServer/SslHTTPConnection.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-01-30 08:40:45 +0100
committerMattes D <github@xoft.cz>2015-01-30 08:40:45 +0100
commitfd49e34e331fc716c48ea1228f24954e9b8b5304 (patch)
tree8d19b61fb5b3052b870ccc9ac956c5069d12dc74 /src/HTTPServer/SslHTTPConnection.cpp
parentUpdated PolarSSL. (diff)
parentFixed listening ports not closed on cServerHandle::Close. (diff)
downloadcuberite-fd49e34e331fc716c48ea1228f24954e9b8b5304.tar
cuberite-fd49e34e331fc716c48ea1228f24954e9b8b5304.tar.gz
cuberite-fd49e34e331fc716c48ea1228f24954e9b8b5304.tar.bz2
cuberite-fd49e34e331fc716c48ea1228f24954e9b8b5304.tar.lz
cuberite-fd49e34e331fc716c48ea1228f24954e9b8b5304.tar.xz
cuberite-fd49e34e331fc716c48ea1228f24954e9b8b5304.tar.zst
cuberite-fd49e34e331fc716c48ea1228f24954e9b8b5304.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: