[Libreoffice-commits] online.git: Branch 'private/Ashod/nonblocking' - Makefile.am net/clientnb.cpp

Michael Meeks michael.meeks at collabora.com
Tue Feb 14 22:57:35 UTC 2017


 Makefile.am      |    4 +-
 net/clientnb.cpp |   99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 1 deletion(-)

New commits:
commit 767e6ef5f1ae60d939029c374b74f29e53afc113
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Feb 14 22:57:03 2017 +0000

    First cut at a Poco based client.

diff --git a/Makefile.am b/Makefile.am
index 7a83508..064d54e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@ SUBDIRS = . test loleaflet
 
 export ENABLE_DEBUG
 
-bin_PROGRAMS = loolwsd loolforkit loolwsd_fuzzer loolmap loolmount looltool loolstress loolnb
+bin_PROGRAMS = loolwsd loolforkit loolwsd_fuzzer loolmap loolmount looltool loolstress loolnb clientnb
 
 dist_bin_SCRIPTS = loolwsd-systemplate-setup
 
@@ -91,6 +91,8 @@ loolwsd_fuzzer_SOURCES = $(loolwsd_sources) \
 
 loolnb_SOURCES = net/loolnb.cpp
 
+clientnb_SOURCES = net/clientnb.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
new file mode 100644
index 0000000..e4a7fc3
--- /dev/null
+++ b/net/clientnb.cpp
@@ -0,0 +1,99 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "config.h"
+
+#include <atomic>
+#include <cerrno>
+#include <cstdlib>
+#include <cstring>
+#include <iostream>
+#include <mutex>
+#include <thread>
+#include <assert.h>
+
+#include <Poco/Net/HTMLForm.h>
+#include <Poco/Net/HTTPClientSession.h>
+#include <Poco/Net/HTTPSClientSession.h>
+#include <Poco/Net/HTTPRequest.h>
+#include <Poco/Net/HTTPResponse.h>
+#include <Poco/Net/FilePartSource.h>
+#include <Poco/Net/SSLManager.h>
+#include <Poco/Net/KeyConsoleHandler.h>
+#include <Poco/Net/AcceptCertificateHandler.h>
+#include <Poco/StreamCopier.h>
+#include <Poco/Thread.h>
+#include <Poco/URI.h>
+#include <Poco/Util/Application.h>
+#include <Poco/Util/HelpFormatter.h>
+#include <Poco/Util/Option.h>
+#include <Poco/Util/OptionSet.h>
+
+using Poco::Net::HTTPClientSession;
+using Poco::Net::HTTPRequest;
+using Poco::Net::HTTPResponse;
+using Poco::Runnable;
+using Poco::Thread;
+using Poco::URI;
+using Poco::Util::Application;
+using Poco::Util::HelpFormatter;
+using Poco::Util::Option;
+using Poco::Util::OptionSet;
+
+constexpr int PortNumber = 9191;
+
+Poco::Net::SocketAddress addr("127.0.0.1", PortNumber);
+
+struct Client : public Poco::Util::Application
+{
+public:
+    int main(const std::vector<std::string>& /* args */) override
+    {
+        const char *hostname = "127.0.0.1";
+        bool https = false;
+        Poco::Net::HTTPClientSession *session;
+        if (https)
+            session = new Poco::Net::HTTPSClientSession(hostname, PortNumber);
+        else
+            session = new Poco::Net::HTTPClientSession(hostname, PortNumber);
+        Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/ping");
+        try {
+            Poco::Net::HTMLForm form;
+            form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART);
+            form.prepareSubmit(request);
+            form.write(session->sendRequest(request));
+        }
+        catch (const Poco::Exception &e)
+        {
+            std::cerr << "Failed to write data: " << e.name() <<
+                  " " << e.message() << "\n";
+            return -1;
+        }
+
+        Poco::Net::HTTPResponse response;
+
+        try {
+            std::cerr << "try to get response\n";
+            std::istream& responseStream = session->receiveResponse(response);
+
+            std::cerr << "Got response '" << responseStream << "'\n";
+        }
+        catch (const Poco::Exception &e)
+        {
+            std::cerr << "Exception converting: " << e.name() <<
+                  " " << e.message() << "\n";
+            return -1;
+        }
+        return 0;
+    }
+};
+
+POCO_APP_MAIN(Client)
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list