[Libreoffice-commits] online.git: Branch 'private/Ashod/nonblocking' - Makefile.am net/clientnb.cpp net/loolnb.cpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Feb 20 03:50:32 UTC 2017
Makefile.am | 4 +++-
net/clientnb.cpp | 39 ++++++++++++++++++++++++++++++++++++---
net/loolnb.cpp | 26 ++++++++++++++++++--------
3 files changed, 57 insertions(+), 12 deletions(-)
New commits:
commit 4bb62d06aaa622307fdd9901b8747c913b31949c
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Feb 19 12:06:45 2017 -0500
nb: websocket echo test
The new test sends data of of 1 byte to
N bytes and expects the exact same data
returned in response.
This tests both buffering sizes and
websocket frames.
Change-Id: Ic6232b4e899d82d90a0ee7c96e4852ffaaf8e958
Reviewed-on: https://gerrit.libreoffice.org/34441
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/Makefile.am b/Makefile.am
index d538593..08a522d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -95,7 +95,9 @@ loolnb_SOURCES = net/loolnb.cpp \
common/Log.cpp \
common/Util.cpp
-clientnb_SOURCES = net/clientnb.cpp
+clientnb_SOURCES = net/clientnb.cpp \
+ common/Log.cpp \
+ common/Util.cpp
# build a binary with no caps to help debugging
loolforkit_nocaps_SOURCES = $(loolforkit_SOURCES)
diff --git a/net/clientnb.cpp b/net/clientnb.cpp
index 7aadaa1..5467fe9 100644
--- a/net/clientnb.cpp
+++ b/net/clientnb.cpp
@@ -37,6 +37,8 @@
#include <Poco/Runnable.h>
#include <Poco/Thread.h>
+#include "Util.hpp"
+
using Poco::Net::HTTPClientSession;
using Poco::Net::HTTPRequest;
using Poco::Net::HTTPResponse;
@@ -192,9 +194,9 @@ struct Client : public Poco::Util::Application
snakes[i].join();
}
- void testWebsocket()
+ void testWebsocketPingPong()
{
- std::cerr << "testwebsocket\n";
+ std::cerr << "testWebsocketPingPong\n";
Session session("ws", EnableHttps);
std::shared_ptr<WebSocket> ws = session.getWebSocket();
@@ -213,6 +215,36 @@ struct Client : public Poco::Util::Application
}
}
+ void testWebsocketEcho()
+ {
+ std::cerr << "testwebsocketEcho\n";
+ Session session("ws", EnableHttps);
+ std::shared_ptr<WebSocket> ws = session.getWebSocket();
+
+ std::vector<char> res;
+ for (size_t i = 1; i < (1 << 14); ++i)
+ {
+ std::cerr << "\n" << i;
+ const std::vector<char> data = Util::rng::getBytes(i);
+ ws->sendFrame(data.data(), data.size(), WebSocket::SendFlags::FRAME_BINARY);
+
+ res.resize(i);
+ int flags;
+ int recvd = ws->receiveFrame(res.data(), res.size(), flags);
+ assert(recvd == static_cast<int>(i));
+
+ if (i == sizeof(size_t))
+ {
+ assert(*reinterpret_cast<const size_t*>(res.data()) ==
+ *reinterpret_cast<const size_t*>(data.data()) + 1);
+ }
+ else
+ {
+ assert(res == data);
+ }
+ }
+ }
+
public:
int main(const std::vector<std::string>& args) override
{
@@ -230,7 +262,8 @@ public:
Poco::Net::SSLManager::instance().initializeClient(nullptr, invalidCertHandler, sslContext);
}
- testWebsocket();
+ testWebsocketPingPong();
+ testWebsocketEcho();
testPing();
testLadder();
diff --git a/net/loolnb.cpp b/net/loolnb.cpp
index b33ed7e..52f048d 100644
--- a/net/loolnb.cpp
+++ b/net/loolnb.cpp
@@ -249,15 +249,25 @@ public:
else
std::cerr << " binary\n";
- // ping pong test
- assert (data.size() >= sizeof(size_t));
- size_t *countPtr = reinterpret_cast<size_t *>(&data[0]);
- size_t count = *countPtr;
- count++;
- std::cerr << "count is " << count << "\n";
std::vector<char> reply;
- reply.insert(reply.end(), reinterpret_cast<char *>(&count),
- reinterpret_cast<char *>(&count) + sizeof(count));
+ if (data.size() == sizeof(size_t))
+ {
+ // ping pong test
+ assert (data.size() >= sizeof(size_t));
+ size_t *countPtr = reinterpret_cast<size_t *>(&data[0]);
+ size_t count = *countPtr;
+ count++;
+ std::cerr << "count is " << count << "\n";
+ reply.insert(reply.end(), reinterpret_cast<char *>(&count),
+ reinterpret_cast<char *>(&count) + sizeof(count));
+ }
+ else
+ {
+ // echo tests
+ reply.insert(reply.end(), data.begin(), data.end());
+ }
+
+ std::cerr << "reply: " << reply.size() << std::endl;
queueWSMessage(reply);
}
More information about the Libreoffice-commits
mailing list