Skip to content
Browse files

fix flushing parent of SSLStream when SSLStream is already flushed

this is important after accepting an SSL connection if the parent
is buffering
  • Loading branch information...
1 parent e976359 commit 22ce904a438664e160c26eeab65b0575b373baff @ccutrer committed Feb 28, 2013
Showing with 24 additions and 3 deletions.
  1. +0 −3 mordor/streams/ssl.cpp
  2. +24 −0 mordor/tests/ssl_stream.cpp
View
3 mordor/streams/ssl.cpp
@@ -456,9 +456,6 @@ SSLStream::flush(bool flushParent)
if (BIO_reset(m_writeBio) != 1)
MORDOR_LOG_TRACE(g_log) << this << " BIO_reset failed ??";
- if (m_writeBuffer.readAvailable() == 0)
- return;
-
while (m_writeBuffer.readAvailable()) {
MORDOR_LOG_TRACE(g_log) << this << " parent()->write("
<< m_writeBuffer.readAvailable() << ")";
View
24 mordor/tests/ssl_stream.cpp
@@ -2,6 +2,7 @@
#include "mordor/iomanager.h"
#include "mordor/parallel.h"
+#include "mordor/streams/buffered.h"
#include "mordor/streams/null.h"
#include "mordor/streams/pipe.h"
#include "mordor/streams/random.h"
@@ -15,6 +16,7 @@ using namespace Mordor;
static void accept(SSLStream::ptr server)
{
server->accept();
+ server->flush();
}
MORDOR_UNITTEST(SSLStream, basic)
@@ -124,6 +126,12 @@ MORDOR_UNITTEST(SSLStream, forceDuplex)
MORDOR_TEST_ASSERT_EQUAL(++sequence, 4);
}
+static void expectUnexpectedEof(Stream::ptr stream)
+{
+ unsigned char buffer;
+ MORDOR_TEST_ASSERT_EQUAL(stream->read(&buffer, 1u), 0u);
+}
+
MORDOR_UNITTEST(SSLStream, incomingDataAfterShutdown)
{
WorkerPool pool;
@@ -140,5 +148,21 @@ MORDOR_UNITTEST(SSLStream, incomingDataAfterShutdown)
MORDOR_TEST_ASSERT_EQUAL(sslclient->write("c", 1u), 1u);
sslclient->flush(false);
+ pool.schedule(boost::bind(&expectUnexpectedEof, sslclient));
sslserver->close();
}
+
+MORDOR_UNITTEST(SSLStream, acceptOverBuffering)
+{
+ WorkerPool pool;
+ std::pair<Stream::ptr, Stream::ptr> pipes = pipeStream();
+ BufferedStream::ptr bufferedStream(new BufferedStream(pipes.first));
+ bufferedStream->allowPartialReads(true);
+
+ SSLStream::ptr sslserver(new SSLStream(bufferedStream, false));
+ SSLStream::ptr sslclient(new SSLStream(pipes.second, true));
+
+ pool.schedule(boost::bind(&accept, sslserver));
+ sslclient->connect();
+ pool.dispatch();
+}

0 comments on commit 22ce904

Please sign in to comment.
Something went wrong with that request. Please try again.