net/clientnb.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++------------ net/loolnb.cpp | 14 ++++---------- 2 files changed, 46 insertions(+), 22 deletions(-)
New commits: commit dc52b96aa756198e75d0fe85a7bbb8db1acf7496 Author: Michael Meeks <michael.me...@collabora.com> Date: Thu Feb 16 14:14:12 2017 +0000 Websocket client test with WS=1 diff --git a/net/clientnb.cpp b/net/clientnb.cpp index aa123e9..de6576c 100644 --- a/net/clientnb.cpp +++ b/net/clientnb.cpp @@ -25,6 +25,7 @@ #include <Poco/Net/HTTPResponse.h> #include <Poco/Net/FilePartSource.h> #include <Poco/Net/SSLManager.h> +#include <Poco/Net/WebSocket.h> #include <Poco/Net/KeyConsoleHandler.h> #include <Poco/Net/AcceptCertificateHandler.h> #include <Poco/StreamCopier.h> @@ -39,6 +40,7 @@ using Poco::Net::HTTPClientSession; using Poco::Net::HTTPRequest; using Poco::Net::HTTPResponse; +using Poco::Net::WebSocket; using Poco::Runnable; using Poco::Thread; using Poco::URI; @@ -107,6 +109,15 @@ struct Session } return number; } + + std::shared_ptr<WebSocket> getWebSocket() + { + _session->setTimeout(Poco::Timespan(10, 0)); + HTTPRequest request(HTTPRequest::HTTP_GET, "/ws"); + HTTPResponse response; + return std::shared_ptr<WebSocket>( + new WebSocket(*_session, request, response)); + } }; struct ThreadWorker : public Runnable @@ -151,25 +162,44 @@ struct Client : public Poco::Util::Application snakes[i].join(); } + void testWebsocket() + { + Session session("ws"); + std::shared_ptr<WebSocket> ws = session.getWebSocket(); + for (size_t i = 0; i < 10; i++) + { + ws->sendFrame(&i, sizeof(i), WebSocket::SendFlags::FRAME_BINARY); + size_t back[5]; + int flags = 0; + int recvd = ws->receiveFrame((void *)back, sizeof(back), flags); + assert(recvd == sizeof(size_t)); + assert(back[0] == i + 1); + } + } + public: int main(const std::vector<std::string>& /* args */) override { - Session first("init"); - Session second("init"); - - int count = 42, back; - first.sendPing(count); - second.sendPing(count + 1); + if (getenv("WS")) + testWebsocket(); + else + { + Session first("init"); + Session second("init"); - back = first.getResponse(); - assert (back == count + 1); + int count = 42, back; + first.sendPing(count); + second.sendPing(count + 1); - back = second.getResponse(); - assert (back == count + 2); + back = first.getResponse(); + assert (back == count + 1); - testLadder(); - testParallel(); + back = second.getResponse(); + assert (back == count + 2); + testLadder(); + testParallel(); + } return 0; } }; diff --git a/net/loolnb.cpp b/net/loolnb.cpp index 5c61a78..01fc3c5 100644 --- a/net/loolnb.cpp +++ b/net/loolnb.cpp @@ -210,15 +210,6 @@ void server(SocketPoll& clientPoller) } } -/// Poll client sockets and do IO. -void pollAndComm(SocketPoll& poller, std::atomic<bool>& stop) -{ - while (!stop) - { - poller.poll(5000); - } -} - int main(int, const char**) { // Used to poll client sockets. @@ -227,7 +218,10 @@ int main(int, const char**) // Start the client polling thread. Thread threadPoll([&poller](std::atomic<bool>& stop) { - pollAndComm(poller, stop); + while (!stop) + { + poller.poll(5000); + } }); // Start the server. _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits