Fix StreambufWSMsg prepare (RIPD-1144).

Return value was set incorrect in some cases.
The buffer was not being prepared.
Add websocket log support.
This commit is contained in:
Miguel Portilla
2016-05-13 17:39:14 -04:00
committed by Nik Bougalis
parent 97c89168f7
commit 154e90b1ca
2 changed files with 17 additions and 12 deletions

View File

@@ -22,6 +22,7 @@
#include <ripple/server/Port.h>
#include <ripple/server/Writer.h>
#include <beast/core/prepare_buffers.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/logic/tribool.hpp>
@@ -82,28 +83,25 @@ public:
prepare(std::size_t bytes,
std::function<void(void)>) override
{
if(sb_.size() == 0)
return { true, {} };
if (sb_.size() == 0)
return{true, {}};
sb_.consume(n_);
boost::tribool done;
// VFALCO TODO respect `bytes` fully
if(bytes < sb_.size())
if (bytes < sb_.size())
{
n_ = bytes;
done = boost::indeterminate;
done = false;
}
else
{
n_ = sb_.size();
done = true;
}
std::vector<boost::asio::const_buffer> vb;
auto const& data = sb_.data();
vb.reserve(std::distance(
data.begin(), data.end()));
std::copy(data.begin(), data.end(),
std::back_inserter(vb));
return { done, vb };
auto const pb = beast::prepare_buffers(n_, sb_.data());
std::vector<boost::asio::const_buffer> vb (
std::distance(pb.begin(), pb.end()));
std::copy(pb.begin(), pb.end(), std::back_inserter(vb));
return{done, vb};
}
};

View File

@@ -271,12 +271,17 @@ ServerHandlerImp::onWSMessage(
sb.commit(boost::asio::buffer_copy(
sb.prepare(n), boost::asio::buffer(p, n)));
});
JLOG(m_journal.trace())
<< "Websocket sending '" << jvResult << "'";
session->send(std::make_shared<
StreambufWSMsg<decltype(sb)>>(std::move(sb)));
session->complete();
return;
}
JLOG(m_journal.trace())
<< "Websocket received '" << jv << "'";
m_jobQueue.postCoro(jtCLIENT, "WS-Client",
[this, session = std::move(session),
jv = std::move(jv)](auto const& jc)
@@ -290,6 +295,8 @@ ServerHandlerImp::onWSMessage(
sb.commit(boost::asio::buffer_copy(
sb.prepare(n), boost::asio::buffer(p, n)));
});
JLOG(m_journal.trace())
<< "Websocket sending '" << jr << "'";
session->send(std::make_shared<
StreambufWSMsg<decltype(sb)>>(std::move(sb)));
session->complete();