net/clientnb.cpp |   26 ++++++++++++++++++++++----
 net/loolnb.cpp   |    4 ++++
 2 files changed, 26 insertions(+), 4 deletions(-)

New commits:
commit 1a9941c23fa538f7d0e8e5622169f8186cc6d37f
Author: Michael Meeks <michael.me...@collabora.com>
Date:   Thu Feb 16 11:52:22 2017 +0000

    Bang on the server with some threads.

diff --git a/net/clientnb.cpp b/net/clientnb.cpp
index 822804d..aa123e9 100644
--- a/net/clientnb.cpp
+++ b/net/clientnb.cpp
@@ -28,7 +28,6 @@
 #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>
@@ -64,6 +63,11 @@ struct Session
         else
             _session = new Poco::Net::HTTPClientSession(HostName, PortNumber);
     }
+    ~Session()
+    {
+        delete _session;
+    }
+
     void sendPing(int i)
     {
         Poco::Net::HTTPRequest request(
@@ -108,7 +112,7 @@ struct Session
 struct ThreadWorker : public Runnable
 {
     const char *_domain;
-               ThreadWorker (const char *domain)
+               ThreadWorker (const char *domain = NULL)
             : _domain(domain)
         {
         }
@@ -116,7 +120,7 @@ struct ThreadWorker : public Runnable
         {
             for (int i = 0; i < 100; ++i)
             {
-                Session ping(_domain);
+                Session ping(_domain ? _domain : "init");
                 ping.sendPing(i);
                 int back = ping.getResponse();
                 assert(back == i + 1);
@@ -128,12 +132,25 @@ struct Client : public Poco::Util::Application
 {
     void testLadder()
     {
-        ThreadWorker ladder("init");
+        ThreadWorker ladder;
         Thread thread;
         thread.start(ladder);
         thread.join();
     }
 
+    void testParallel()
+    {
+        const int num = 10;
+        Thread snakes[num];
+        ThreadWorker ladders[num];
+
+        for (size_t i = 0; i < num; i++)
+            snakes[i].start(ladders[i]);
+
+        for (int i = 0; i < num; i++)
+            snakes[i].join();
+    }
+
 public:
     int main(const std::vector<std::string>& /* args */) override
     {
@@ -151,6 +168,7 @@ public:
         assert (back == count + 2);
 
         testLadder();
+        testParallel();
 
         return 0;
     }
diff --git a/net/loolnb.cpp b/net/loolnb.cpp
index 7c4f23f..5c61a78 100644
--- a/net/loolnb.cpp
+++ b/net/loolnb.cpp
@@ -22,6 +22,8 @@
 #include <Poco/Net/SocketAddress.h>
 #include <Poco/Net/HTTPRequest.h>
 #include <Poco/StringTokenizer.h>
+#include <Poco/Runnable.h>
+#include <Poco/Thread.h>
 
 using Poco::MemoryInputStream;
 using Poco::StringTokenizer;
@@ -75,6 +77,8 @@ public:
     }
 };
 
+// FIXME: use Poco Thread instead (?)
+
 /// Generic thread class.
 class Thread
 {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to