Index: test/.copyright
===================================================================
--- test/.copyright	(revision 2)
+++ test/.copyright	(revision 2)
@@ -0,0 +1,23 @@
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
Index: test/.copyright
===================================================================
--- test/.copyright	(revision 2)
+++ 	(revision )
@@ -1,23 +1,0 @@
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-
-// 1. Redistributions of source code must retain the above copyright notice, this
-//    list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-//    this list of conditions and the following disclaimer in the documentation
-//    and/or other materials provided with the distribution.
-
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// The views and conclusions contained in the software and documentation are those
-// of the authors and should not be interpreted as representing official policies,
-// either expressed or implied, of the FreeBSD Project.
Index: test/.srcmessage
===================================================================
--- test/.srcmessage	(revision 2)
+++ test/.srcmessage	(revision 2)
@@ -0,0 +1,1 @@
+// This file is part of VSCPL, a simple cross-platform utility library
Index: test/.srcmessage
===================================================================
--- test/.srcmessage	(revision 2)
+++ 	(revision )
@@ -1,1 +1,0 @@
-// This file is part of VSCPL, a simple cross-platform utility library
Index: test/Makefile.am
===================================================================
--- test/Makefile.am	(revision 25)
+++ test/Makefile.am	(revision 25)
@@ -0,0 +1,33 @@
+AM_CPPFLAGS=-I$(top_srcdir)/src -I$(top_builddir)/src
+
+noinst_PROGRAMS=testthread testmutex testcondvar testevent testlocsock testblkstream testmultiserver testmulticlient
+
+if TARGET_API_POSIX
+noinst_PROGRAMS+=testrandom
+endif
+
+LDADD=../src/hu/varadiistvan/scpl/libvscpl.la
+if TARGET_API_POSIX
+LDADD+=-lpthread
+endif
+if TARGET_API_WIN32
+AM_LDFLAGS=-static -static-libgcc -static-libstdc++
+endif
+
+testthread_SOURCES=testthread.cc
+
+testmutex_SOURCES=testmutex.cc
+
+testcondvar_SOURCES=testcondvar.cc
+
+testevent_SOURCES=testevent.cc
+
+testlocsock_SOURCES=testlocsock.cc
+
+testblkstream_SOURCES=testblkstream.cc
+
+testrandom_SOURCES=testrandom.cc
+
+testmultiserver_SOURCES=testmultiserver.cc
+
+testmulticlient_SOURCES=testmulticlient.cc
Index: test/Makefile.am
===================================================================
--- test/Makefile.am	(revision 14)
+++ 	(revision )
@@ -1,33 +1,0 @@
-INCLUDES=-I$(top_srcdir)/src -I$(top_builddir)/src
-
-noinst_PROGRAMS=testthread testmutex testcondvar testevent testlocsock testblkstream testmultiserver testmulticlient
-
-if TARGET_API_POSIX
-noinst_PROGRAMS+=testrandom
-endif
-
-LDADD=../src/hu/varadiistvan/scpl/libvscpl.la
-if TARGET_API_POSIX
-LDADD+=-lpthread
-endif
-if TARGET_API_WIN32
-AM_LDFLAGS=-static -static-libgcc -static-libstdc++
-endif
-
-testthread_SOURCES=testthread.cc
-
-testmutex_SOURCES=testmutex.cc
-
-testcondvar_SOURCES=testcondvar.cc
-
-testevent_SOURCES=testevent.cc
-
-testlocsock_SOURCES=testlocsock.cc
-
-testblkstream_SOURCES=testblkstream.cc
-
-testrandom_SOURCES=testrandom.cc
-
-testmultiserver_SOURCES=testmultiserver.cc
-
-testmulticlient_SOURCES=testmulticlient.cc
Index: test/testblkstream.cc
===================================================================
--- test/testblkstream.cc	(revision 10)
+++ test/testblkstream.cc	(revision 10)
@@ -0,0 +1,341 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include <hu/varadiistvan/scpl/io/Waiter.h>
+#include <hu/varadiistvan/scpl/io/LocalServerSocket.h>
+#include <hu/varadiistvan/scpl/io/LocalAcceptor.h>
+#include <hu/varadiistvan/scpl/io/LocalSocket.h>
+#include <hu/varadiistvan/scpl/io/LocalClientSocket.h>
+#include <hu/varadiistvan/scpl/io/LocalConnector.h>
+#include <hu/varadiistvan/scpl/io/DataStream.h>
+#include <hu/varadiistvan/scpl/io/WaitableEvent.h>
+
+#include <hu/varadiistvan/scpl/Thread.h>
+#include <hu/varadiistvan/scpl/PseudoRandom.h>
+
+#include <cstdlib>
+#include <cstdio>
+#include <cassert>
+
+#include <signal.h>
+
+#include <sys/time.h>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::Waiter;
+using hu::varadiistvan::scpl::io::LocalServerSocket;
+using hu::varadiistvan::scpl::io::LocalAcceptor;
+using hu::varadiistvan::scpl::io::LocalSocket;
+using hu::varadiistvan::scpl::io::LocalClientSocket;
+using hu::varadiistvan::scpl::io::LocalConnector;
+using hu::varadiistvan::scpl::io::BufferedStream;
+using hu::varadiistvan::scpl::io::DataStream;
+
+using hu::varadiistvan::scpl::Thread;
+using hu::varadiistvan::scpl::PseudoRandom;
+
+using std::min;
+
+//------------------------------------------------------------------------------
+
+class TestThread : public Thread
+{
+private:
+    static const uint8_t OP_ADD = 1;
+
+    static const uint8_t OP_SUB = 2;
+
+    static const uint8_t OP_MUL = 3;
+
+    static const uint8_t OP_DIV = 4;
+
+private:
+    static int32_t perform(int32_t value, uint8_t operation, int32_t x);
+
+    DataStream* dataStream;
+
+protected:
+    TestThread();
+
+public:
+    void interrupt();
+
+protected:
+    void communicate(BufferedStream& stream, unsigned seed, bool isClient);
+};
+
+//------------------------------------------------------------------------------
+
+inline int32_t TestThread::perform(int32_t value, uint8_t operation, int32_t x)
+{
+    switch (operation) {
+      case OP_ADD:
+        return value + x;
+      case OP_SUB:
+        return value - x;
+      case OP_MUL:
+        return value * x;
+      case OP_DIV:
+        return value / x;
+      default:
+        return value;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+inline TestThread::TestThread() :
+    dataStream(0)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline void TestThread::interrupt()
+{
+    if (dataStream!=0) dataStream->interrupt();
+}
+
+//------------------------------------------------------------------------------
+
+void TestThread::communicate(BufferedStream& stream, unsigned seed, bool isClient)
+{
+    static const size_t reportInterval = 100000;
+
+    const char* prefix = isClient ? "Client" : "Server";
+
+    dataStream = new DataStream(stream);
+    PseudoRandom random(seed);
+
+    bool first = true;
+
+    size_t numRequests = 0;
+    size_t nextReportRequests = reportInterval;
+
+    int32_t value = 0;
+    if (isClient) {
+        value = random.next();
+        dataStream->writeS32(value);
+    } else {
+        value = dataStream->readS32();
+    }
+
+    int32_t newValue = value;
+
+    while(*dataStream) {
+        if (!first || isClient) {
+            unsigned numOperations = random.nextUnsigned(20, 1);
+            dataStream->writeU16(numOperations);
+            //printf("%s: numOperations=%u\n", prefix, numOperations);
+            for(unsigned i = 0; i<numOperations; ++i) {
+                double r = random.nextDouble();
+                uint8_t operation =
+                    (r<0.4) ? OP_ADD : ((r<0.8) ? OP_SUB :
+                                        ((r<0.98) ? OP_MUL : OP_DIV));
+                int32_t x = random.next();
+
+                dataStream->writeU8(operation);
+                dataStream->writeS32(x);
+
+                newValue = perform(newValue, operation, x);
+            }
+            if (!dataStream->flush()) break;
+
+            if (isClient) {
+                value = newValue;
+                ++numRequests;
+                if (numRequests>=nextReportRequests) {
+                    printf("%s: after %lu requests, value=%d\n",
+                           prefix, static_cast<unsigned long>(numRequests),
+                           value);
+                    nextReportRequests += reportInterval;
+                }
+            }
+        }
+
+        unsigned numOperations = dataStream->readU16();
+        for (unsigned i = 0; *dataStream && i<numOperations; ++i) {
+            uint8_t operation = dataStream->readU8();
+            int32_t x = dataStream->readS32();
+            newValue = perform(newValue, operation, x);
+        }
+
+        if (*dataStream) {
+            if (!isClient) {
+                value = newValue;
+                ++numRequests;
+                if (numRequests>=nextReportRequests) {
+                    printf("%s: after %lu requests, value=%d\n",
+                           prefix, static_cast<unsigned long>(numRequests),
+                           value);
+                    nextReportRequests += reportInterval;
+                }
+            }
+        }
+
+
+        first = false;
+    }
+
+    if (dataStream->failed()) {
+        printf("%s: data stream failed with error code: %lu\n", prefix,
+               static_cast<unsigned long>(dataStream->getErrorCode()));
+    } else if (dataStream->isInterrupted()) {
+        printf("%s: data stream was interrupted\n", prefix);
+    }
+
+    printf("%s: value=%d, %lu requests\n", prefix, value,
+           static_cast<unsigned long>(numRequests));
+}
+
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class ServerThread : public TestThread
+{
+public:
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+void ServerThread::run()
+{
+    Waiter waiter;
+
+    unsigned seed = static_cast<unsigned>(time(0)*1.2);
+    printf("ServerThread::run: seed=%u\n", seed);
+
+    LocalServerSocket serverSocket("test", &waiter);
+    LocalAcceptor& acceptor = serverSocket.getAcceptor();
+
+    while(!acceptor.accept()) {
+        if (acceptor.failed()) {
+            printf("ServerThread::run: acceptor failed...: %lu\n",
+                   (unsigned long)acceptor.getErrorCode());
+            return;
+        }
+        printf("ServerThread::run: waiting...\n");
+        waiter.wait();
+    }
+
+    printf("ServerThread::run: waiting done, received connection\n");
+    LocalSocket* socket = acceptor.getSocket();
+
+    acceptor.accept();
+
+    communicate(*socket, seed, false);
+
+    delete socket;
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class ClientThread : public TestThread
+{
+public:
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+void ClientThread::run()
+{
+    Waiter waiter;
+
+    unsigned seed = static_cast<unsigned>(time(0)*1.8);
+    printf("ClientThread::run: seed=%u\n", seed);
+
+    printf("ClientThread::run: sleeping\n");
+    sleep(500);
+    printf("ClientThread::run: connecting\n");
+
+    LocalClientSocket socket("test", &waiter);
+
+    LocalConnector& connector = socket.getConnector();
+
+    while(!connector.connect()) {
+        if (connector.failed()) {
+            printf("ClientThread::run: connector failed...\n");
+            return;
+        }
+        printf("ClientThread::run: waiting...\n");
+        waiter.wait();
+    }
+
+    printf("ClientThread::run: connected\n");
+
+    communicate(socket, seed, true);
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+int main()
+{
+#if TARGET_API_POSIX
+    signal(SIGPIPE, SIG_IGN);
+#endif
+
+    ServerThread serverThread;
+    ClientThread clientThread;
+
+    printf("Starting threads\n");
+    serverThread.start();
+    clientThread.start();
+
+
+    Thread::sleep(60000);
+    //Thread::sleep(1000);
+    printf("Signalling the client thread\n");
+    //serverThread.interrupt();
+    clientThread.interrupt();
+    printf("Signalled the client thread\n");
+
+    printf("Waiting for the client thread\n");
+    clientThread.join();
+    printf("Waiting for the server thread\n");
+    serverThread.join();
+    printf("Both threads returned\n");
+
+    return 0;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: test/testblkstream.cc
===================================================================
--- test/testblkstream.cc	(revision 10)
+++ 	(revision )
@@ -1,341 +1,0 @@
-// Copyright (c) 2012 by István Váradi
-
-// This file is part of libxplcommon, a common utility library for
-// development related to X-Plane
-
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-
-// 1. Redistributions of source code must retain the above copyright notice, this
-//    list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-//    this list of conditions and the following disclaimer in the documentation
-//    and/or other materials provided with the distribution.
-
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// The views and conclusions contained in the software and documentation are those
-// of the authors and should not be interpreted as representing official policies,
-// either expressed or implied, of the FreeBSD Project.
-
-//------------------------------------------------------------------------------
-
-#include <hu/varadiistvan/scpl/io/Waiter.h>
-#include <hu/varadiistvan/scpl/io/LocalServerSocket.h>
-#include <hu/varadiistvan/scpl/io/LocalAcceptor.h>
-#include <hu/varadiistvan/scpl/io/LocalSocket.h>
-#include <hu/varadiistvan/scpl/io/LocalClientSocket.h>
-#include <hu/varadiistvan/scpl/io/LocalConnector.h>
-#include <hu/varadiistvan/scpl/io/DataStream.h>
-#include <hu/varadiistvan/scpl/io/WaitableEvent.h>
-
-#include <hu/varadiistvan/scpl/Thread.h>
-#include <hu/varadiistvan/scpl/PseudoRandom.h>
-
-#include <cstdlib>
-#include <cstdio>
-#include <cassert>
-
-#include <signal.h>
-
-#include <sys/time.h>
-
-//------------------------------------------------------------------------------
-
-using hu::varadiistvan::scpl::io::Waiter;
-using hu::varadiistvan::scpl::io::LocalServerSocket;
-using hu::varadiistvan::scpl::io::LocalAcceptor;
-using hu::varadiistvan::scpl::io::LocalSocket;
-using hu::varadiistvan::scpl::io::LocalClientSocket;
-using hu::varadiistvan::scpl::io::LocalConnector;
-using hu::varadiistvan::scpl::io::BufferedStream;
-using hu::varadiistvan::scpl::io::DataStream;
-
-using hu::varadiistvan::scpl::Thread;
-using hu::varadiistvan::scpl::PseudoRandom;
-
-using std::min;
-
-//------------------------------------------------------------------------------
-
-class TestThread : public Thread
-{
-private:
-    static const uint8_t OP_ADD = 1;
-
-    static const uint8_t OP_SUB = 2;
-
-    static const uint8_t OP_MUL = 3;
-
-    static const uint8_t OP_DIV = 4;
-
-private:
-    static int32_t perform(int32_t value, uint8_t operation, int32_t x);
-
-    DataStream* dataStream;
-
-protected:
-    TestThread();
-
-public:
-    void interrupt();
-
-protected:
-    void communicate(BufferedStream& stream, unsigned seed, bool isClient);
-};
-
-//------------------------------------------------------------------------------
-
-inline int32_t TestThread::perform(int32_t value, uint8_t operation, int32_t x)
-{
-    switch (operation) {
-      case OP_ADD:
-        return value + x;
-      case OP_SUB:
-        return value - x;
-      case OP_MUL:
-        return value * x;
-      case OP_DIV:
-        return value / x;
-      default:
-        return value;
-    }
-}
-
-//------------------------------------------------------------------------------
-
-inline TestThread::TestThread() :
-    dataStream(0)
-{
-}
-
-//------------------------------------------------------------------------------
-
-inline void TestThread::interrupt()
-{
-    if (dataStream!=0) dataStream->interrupt();
-}
-
-//------------------------------------------------------------------------------
-
-void TestThread::communicate(BufferedStream& stream, unsigned seed, bool isClient)
-{
-    static const size_t reportInterval = 100000;
-
-    const char* prefix = isClient ? "Client" : "Server";
-
-    dataStream = new DataStream(stream);
-    PseudoRandom random(seed);
-
-    bool first = true;
-
-    size_t numRequests = 0;
-    size_t nextReportRequests = reportInterval;
-
-    int32_t value = 0;
-    if (isClient) {
-        value = random.next();
-        dataStream->writeS32(value);
-    } else {
-        value = dataStream->readS32();
-    }
-
-    int32_t newValue = value;
-
-    while(*dataStream) {
-        if (!first || isClient) {
-            unsigned numOperations = random.nextUnsigned(20, 1);
-            dataStream->writeU16(numOperations);
-            //printf("%s: numOperations=%u\n", prefix, numOperations);
-            for(unsigned i = 0; i<numOperations; ++i) {
-                double r = random.nextDouble();
-                uint8_t operation =
-                    (r<0.4) ? OP_ADD : ((r<0.8) ? OP_SUB :
-                                        ((r<0.98) ? OP_MUL : OP_DIV));
-                int32_t x = random.next();
-
-                dataStream->writeU8(operation);
-                dataStream->writeS32(x);
-
-                newValue = perform(newValue, operation, x);
-            }
-            if (!dataStream->flush()) break;
-
-            if (isClient) {
-                value = newValue;
-                ++numRequests;
-                if (numRequests>=nextReportRequests) {
-                    printf("%s: after %lu requests, value=%d\n",
-                           prefix, static_cast<unsigned long>(numRequests),
-                           value);
-                    nextReportRequests += reportInterval;
-                }
-            }
-        }
-
-        unsigned numOperations = dataStream->readU16();
-        for (unsigned i = 0; *dataStream && i<numOperations; ++i) {
-            uint8_t operation = dataStream->readU8();
-            int32_t x = dataStream->readS32();
-            newValue = perform(newValue, operation, x);
-        }
-
-        if (*dataStream) {
-            if (!isClient) {
-                value = newValue;
-                ++numRequests;
-                if (numRequests>=nextReportRequests) {
-                    printf("%s: after %lu requests, value=%d\n",
-                           prefix, static_cast<unsigned long>(numRequests),
-                           value);
-                    nextReportRequests += reportInterval;
-                }
-            }
-        }
-
-
-        first = false;
-    }
-
-    if (dataStream->failed()) {
-        printf("%s: data stream failed with error code: %lu\n", prefix,
-               static_cast<unsigned long>(dataStream->getErrorCode()));
-    } else if (dataStream->isInterrupted()) {
-        printf("%s: data stream was interrupted\n", prefix);
-    }
-
-    printf("%s: value=%d, %lu requests\n", prefix, value,
-           static_cast<unsigned long>(numRequests));
-}
-
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-class ServerThread : public TestThread
-{
-public:
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-void ServerThread::run()
-{
-    Waiter waiter;
-
-    unsigned seed = static_cast<unsigned>(time(0)*1.2);
-    printf("ServerThread::run: seed=%u\n", seed);
-
-    LocalServerSocket serverSocket("test", &waiter);
-    LocalAcceptor& acceptor = serverSocket.getAcceptor();
-
-    while(!acceptor.accept()) {
-        if (acceptor.failed()) {
-            printf("ServerThread::run: acceptor failed...: %lu\n",
-                   (unsigned long)acceptor.getErrorCode());
-            return;
-        }
-        printf("ServerThread::run: waiting...\n");
-        waiter.wait();
-    }
-
-    printf("ServerThread::run: waiting done, received connection\n");
-    LocalSocket* socket = acceptor.getSocket();
-
-    acceptor.accept();
-
-    communicate(*socket, seed, false);
-
-    delete socket;
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-class ClientThread : public TestThread
-{
-public:
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-void ClientThread::run()
-{
-    Waiter waiter;
-
-    unsigned seed = static_cast<unsigned>(time(0)*1.8);
-    printf("ClientThread::run: seed=%u\n", seed);
-
-    printf("ClientThread::run: sleeping\n");
-    sleep(500);
-    printf("ClientThread::run: connecting\n");
-
-    LocalClientSocket socket("test", &waiter);
-
-    LocalConnector& connector = socket.getConnector();
-
-    while(!connector.connect()) {
-        if (connector.failed()) {
-            printf("ClientThread::run: connector failed...\n");
-            return;
-        }
-        printf("ClientThread::run: waiting...\n");
-        waiter.wait();
-    }
-
-    printf("ClientThread::run: connected\n");
-
-    communicate(socket, seed, true);
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-int main()
-{
-#if TARGET_API_POSIX
-    signal(SIGPIPE, SIG_IGN);
-#endif
-
-    ServerThread serverThread;
-    ClientThread clientThread;
-
-    printf("Starting threads\n");
-    serverThread.start();
-    clientThread.start();
-
-
-    Thread::sleep(60000);
-    //Thread::sleep(1000);
-    printf("Signalling the client thread\n");
-    //serverThread.interrupt();
-    clientThread.interrupt();
-    printf("Signalled the client thread\n");
-
-    printf("Waiting for the client thread\n");
-    clientThread.join();
-    printf("Waiting for the server thread\n");
-    serverThread.join();
-    printf("Both threads returned\n");
-
-    return 0;
-}
-
-//------------------------------------------------------------------------------
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: test/testcondvar.cc
===================================================================
--- test/testcondvar.cc	(revision 5)
+++ test/testcondvar.cc	(revision 5)
@@ -0,0 +1,184 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include <hu/varadiistvan/scpl/Thread.h>
+#include <hu/varadiistvan/scpl/Mutex.h>
+#include <hu/varadiistvan/scpl/CondVar.h>
+
+#include <cstdlib>
+#include <cstdio>
+#include <cassert>
+
+#include <signal.h>
+
+#include <sys/time.h>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::Thread;
+using hu::varadiistvan::scpl::Mutex;
+using hu::varadiistvan::scpl::CondVar;
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class Thread1 : public Thread
+{
+private:
+    char id;
+
+    Mutex& mutex;
+
+    CondVar& condVar;
+
+public:
+    Thread1(char id, Mutex& mutex, CondVar& condVar);
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+inline Thread1::Thread1(char id, Mutex& mutex, CondVar& condVar) :
+    id(id),
+    mutex(mutex),
+    condVar(condVar)
+{
+}
+
+//------------------------------------------------------------------------------
+
+void Thread1::run()
+{
+    printf("Thread1[%c]::run: locking, and waiting on the condition\n", id);
+    mutex.lock();
+    condVar.wait(mutex);
+    printf("Thread1[%c]::run: condition received, waiting again\n", id);
+    condVar.wait(mutex);
+    printf("Thread1[%c]::run: condition received again, waiting with timeout\n", id);
+
+    bool result = condVar.wait(mutex, 5000);
+    printf("Thread1[%c]::run: waiting finished, %s\n", id,
+           result ? "received condition" : "timed out");
+    mutex.unlock();
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class Thread2 : public Thread
+{
+private:
+    Mutex& mutex;
+
+    CondVar& condVar;
+
+public:
+    Thread2(Mutex& mutex, CondVar& condVar);
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+inline Thread2::Thread2(Mutex& mutex, CondVar& condVar) :
+    mutex(mutex),
+    condVar(condVar)
+{
+}
+
+//------------------------------------------------------------------------------
+
+void Thread2::run()
+{
+    printf("Thread2::run: sleeping\n");
+    sleep(2000);
+    printf("------------------------------------------------------------\n");
+
+    printf("Thread2::run: woke up, signalling condition variable\n");
+    condVar.signal();
+
+    printf("Thread2::run: sleeping...\n");
+    sleep(2000);
+    printf("------------------------------------------------------------\n");
+
+    printf("Thread2::run: woke up, broadcasting condition variable\n");
+    condVar.broadcast();
+
+    printf("Thread2::run: sleeping...\n");
+    sleep(2000);
+    printf("------------------------------------------------------------\n");
+
+    printf("Thread2::run: woke up, signalling condition variable\n");
+    condVar.signal();
+
+    printf("Thread2::run: sleeping...\n");
+    sleep(2000);
+    printf("------------------------------------------------------------\n");
+
+    printf("Thread2::run: woke up, signalling condition variable\n");
+    condVar.signal();
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+int main()
+{
+    Mutex mutex;
+    CondVar condVar;
+
+    Thread1 thread1('A', mutex, condVar);
+    Thread1 thread1a('B', mutex, condVar);
+    Thread2 thread2(mutex, condVar);
+
+    printf("Starting threads\n");
+    thread1.start();
+    thread1a.start();
+    thread2.start();
+
+    printf("Waiting for thread1\n");
+    thread1.join();
+    thread1a.join();
+    printf("Waiting for thread2\n");
+    thread2.join();
+    printf("Both threads returned\n");
+
+    return 0;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: test/testcondvar.cc
===================================================================
--- test/testcondvar.cc	(revision 5)
+++ 	(revision )
@@ -1,184 +1,0 @@
-// Copyright (c) 2012 by István Váradi
-
-// This file is part of libxplcommon, a common utility library for
-// development related to X-Plane
-
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-
-// 1. Redistributions of source code must retain the above copyright notice, this
-//    list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-//    this list of conditions and the following disclaimer in the documentation
-//    and/or other materials provided with the distribution.
-
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// The views and conclusions contained in the software and documentation are those
-// of the authors and should not be interpreted as representing official policies,
-// either expressed or implied, of the FreeBSD Project.
-
-//------------------------------------------------------------------------------
-
-#include <hu/varadiistvan/scpl/Thread.h>
-#include <hu/varadiistvan/scpl/Mutex.h>
-#include <hu/varadiistvan/scpl/CondVar.h>
-
-#include <cstdlib>
-#include <cstdio>
-#include <cassert>
-
-#include <signal.h>
-
-#include <sys/time.h>
-
-//------------------------------------------------------------------------------
-
-using hu::varadiistvan::scpl::Thread;
-using hu::varadiistvan::scpl::Mutex;
-using hu::varadiistvan::scpl::CondVar;
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-class Thread1 : public Thread
-{
-private:
-    char id;
-
-    Mutex& mutex;
-
-    CondVar& condVar;
-
-public:
-    Thread1(char id, Mutex& mutex, CondVar& condVar);
-
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-inline Thread1::Thread1(char id, Mutex& mutex, CondVar& condVar) :
-    id(id),
-    mutex(mutex),
-    condVar(condVar)
-{
-}
-
-//------------------------------------------------------------------------------
-
-void Thread1::run()
-{
-    printf("Thread1[%c]::run: locking, and waiting on the condition\n", id);
-    mutex.lock();
-    condVar.wait(mutex);
-    printf("Thread1[%c]::run: condition received, waiting again\n", id);
-    condVar.wait(mutex);
-    printf("Thread1[%c]::run: condition received again, waiting with timeout\n", id);
-
-    bool result = condVar.wait(mutex, 5000);
-    printf("Thread1[%c]::run: waiting finished, %s\n", id,
-           result ? "received condition" : "timed out");
-    mutex.unlock();
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-class Thread2 : public Thread
-{
-private:
-    Mutex& mutex;
-
-    CondVar& condVar;
-
-public:
-    Thread2(Mutex& mutex, CondVar& condVar);
-
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-inline Thread2::Thread2(Mutex& mutex, CondVar& condVar) :
-    mutex(mutex),
-    condVar(condVar)
-{
-}
-
-//------------------------------------------------------------------------------
-
-void Thread2::run()
-{
-    printf("Thread2::run: sleeping\n");
-    sleep(2000);
-    printf("------------------------------------------------------------\n");
-
-    printf("Thread2::run: woke up, signalling condition variable\n");
-    condVar.signal();
-
-    printf("Thread2::run: sleeping...\n");
-    sleep(2000);
-    printf("------------------------------------------------------------\n");
-
-    printf("Thread2::run: woke up, broadcasting condition variable\n");
-    condVar.broadcast();
-
-    printf("Thread2::run: sleeping...\n");
-    sleep(2000);
-    printf("------------------------------------------------------------\n");
-
-    printf("Thread2::run: woke up, signalling condition variable\n");
-    condVar.signal();
-
-    printf("Thread2::run: sleeping...\n");
-    sleep(2000);
-    printf("------------------------------------------------------------\n");
-
-    printf("Thread2::run: woke up, signalling condition variable\n");
-    condVar.signal();
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-int main()
-{
-    Mutex mutex;
-    CondVar condVar;
-
-    Thread1 thread1('A', mutex, condVar);
-    Thread1 thread1a('B', mutex, condVar);
-    Thread2 thread2(mutex, condVar);
-
-    printf("Starting threads\n");
-    thread1.start();
-    thread1a.start();
-    thread2.start();
-
-    printf("Waiting for thread1\n");
-    thread1.join();
-    thread1a.join();
-    printf("Waiting for thread2\n");
-    thread2.join();
-    printf("Both threads returned\n");
-
-    return 0;
-}
-
-//------------------------------------------------------------------------------
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: test/testevent.cc
===================================================================
--- test/testevent.cc	(revision 7)
+++ test/testevent.cc	(revision 7)
@@ -0,0 +1,194 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include <hu/varadiistvan/scpl/io/Waiter.h>
+#include <hu/varadiistvan/scpl/io/WaitableEvent.h>
+
+#include <hu/varadiistvan/scpl/Thread.h>
+
+#include <cstdio>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::Thread;
+using hu::varadiistvan::scpl::io::Waiter;
+using hu::varadiistvan::scpl::io::WaitableEvent;
+
+//------------------------------------------------------------------------------
+
+class ServerThread : public Thread
+{
+private:
+    Waiter waiter;
+
+    WaitableEvent event;
+
+public:
+    ServerThread();
+
+    WaitableEvent& getEvent();
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+inline ServerThread::ServerThread() :
+    event(&waiter)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline WaitableEvent& ServerThread::getEvent()
+{
+    return event;
+}
+
+//------------------------------------------------------------------------------
+
+void ServerThread::run()
+{
+    printf("ServerThread::run\n");
+    while(!event.check()) {
+        printf("ServerThread::run: waiting...\n");
+        waiter.wait();
+        printf("ServerThread::run: waiting done\n");
+    }
+    printf("ServerThread::run: finished\n");
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class BlockingServerThread : public Thread
+{
+private:
+    WaitableEvent event;
+
+public:
+    WaitableEvent& getEvent();
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+inline WaitableEvent& BlockingServerThread::getEvent()
+{
+    return event;
+}
+
+//------------------------------------------------------------------------------
+
+void BlockingServerThread::run()
+{
+    printf("BlockingServerThread::run: waiting...\n");
+    if (event.check()) {
+        printf("BlockingServerThread::run: waiting done\n");
+    } else {
+        printf("BlockingServerThread::run: waiting failed\n");
+    }
+    printf("BlockingServerThread::run: finished\n");
+}
+
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class ClientThread : public Thread
+{
+private:
+    WaitableEvent& event;
+
+public:
+    ClientThread(WaitableEvent& event);
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+inline ClientThread::ClientThread(WaitableEvent& event) :
+    event(event)
+{
+}
+
+//------------------------------------------------------------------------------
+
+void ClientThread::run()
+{
+    printf("ClientThread::run: sleeping\n");
+    sleep(2000);
+    printf("ClientThread::run: firing event\n");
+    event.fire();
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+template <class Server> void runTest()
+{
+    Server serverThread;
+    ClientThread clientThread(serverThread.getEvent());
+
+    printf("Starting threads\n");
+    serverThread.start();
+    clientThread.start();
+
+    printf("Waiting for the client thread\n");
+    clientThread.join();
+    printf("Waiting for the server thread\n");
+    serverThread.join();
+    printf("Both threads returned\n");
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+int main()
+{
+    printf("Running the event test with a non-blocking WaitableEvent\n\n");
+    runTest<ServerThread>();
+
+    printf("\n\nRunning the event test with a blocking WaitableEvent\n\n");
+    runTest<BlockingServerThread>();
+
+    return 0;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: test/testevent.cc
===================================================================
--- test/testevent.cc	(revision 7)
+++ 	(revision )
@@ -1,194 +1,0 @@
-// Copyright (c) 2012 by István Váradi
-
-// This file is part of libxplcommon, a common utility library for
-// development related to X-Plane
-
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-
-// 1. Redistributions of source code must retain the above copyright notice, this
-//    list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-//    this list of conditions and the following disclaimer in the documentation
-//    and/or other materials provided with the distribution.
-
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// The views and conclusions contained in the software and documentation are those
-// of the authors and should not be interpreted as representing official policies,
-// either expressed or implied, of the FreeBSD Project.
-
-//------------------------------------------------------------------------------
-
-#include <hu/varadiistvan/scpl/io/Waiter.h>
-#include <hu/varadiistvan/scpl/io/WaitableEvent.h>
-
-#include <hu/varadiistvan/scpl/Thread.h>
-
-#include <cstdio>
-
-//------------------------------------------------------------------------------
-
-using hu::varadiistvan::scpl::Thread;
-using hu::varadiistvan::scpl::io::Waiter;
-using hu::varadiistvan::scpl::io::WaitableEvent;
-
-//------------------------------------------------------------------------------
-
-class ServerThread : public Thread
-{
-private:
-    Waiter waiter;
-
-    WaitableEvent event;
-
-public:
-    ServerThread();
-
-    WaitableEvent& getEvent();
-
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-inline ServerThread::ServerThread() :
-    event(&waiter)
-{
-}
-
-//------------------------------------------------------------------------------
-
-inline WaitableEvent& ServerThread::getEvent()
-{
-    return event;
-}
-
-//------------------------------------------------------------------------------
-
-void ServerThread::run()
-{
-    printf("ServerThread::run\n");
-    while(!event.check()) {
-        printf("ServerThread::run: waiting...\n");
-        waiter.wait();
-        printf("ServerThread::run: waiting done\n");
-    }
-    printf("ServerThread::run: finished\n");
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-class BlockingServerThread : public Thread
-{
-private:
-    WaitableEvent event;
-
-public:
-    WaitableEvent& getEvent();
-
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-inline WaitableEvent& BlockingServerThread::getEvent()
-{
-    return event;
-}
-
-//------------------------------------------------------------------------------
-
-void BlockingServerThread::run()
-{
-    printf("BlockingServerThread::run: waiting...\n");
-    if (event.check()) {
-        printf("BlockingServerThread::run: waiting done\n");
-    } else {
-        printf("BlockingServerThread::run: waiting failed\n");
-    }
-    printf("BlockingServerThread::run: finished\n");
-}
-
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-class ClientThread : public Thread
-{
-private:
-    WaitableEvent& event;
-
-public:
-    ClientThread(WaitableEvent& event);
-
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-inline ClientThread::ClientThread(WaitableEvent& event) :
-    event(event)
-{
-}
-
-//------------------------------------------------------------------------------
-
-void ClientThread::run()
-{
-    printf("ClientThread::run: sleeping\n");
-    sleep(2000);
-    printf("ClientThread::run: firing event\n");
-    event.fire();
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-template <class Server> void runTest()
-{
-    Server serverThread;
-    ClientThread clientThread(serverThread.getEvent());
-
-    printf("Starting threads\n");
-    serverThread.start();
-    clientThread.start();
-
-    printf("Waiting for the client thread\n");
-    clientThread.join();
-    printf("Waiting for the server thread\n");
-    serverThread.join();
-    printf("Both threads returned\n");
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-int main()
-{
-    printf("Running the event test with a non-blocking WaitableEvent\n\n");
-    runTest<ServerThread>();
-
-    printf("\n\nRunning the event test with a blocking WaitableEvent\n\n");
-    runTest<BlockingServerThread>();
-
-    return 0;
-}
-
-//------------------------------------------------------------------------------
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: test/testlocsock.cc
===================================================================
--- test/testlocsock.cc	(revision 8)
+++ test/testlocsock.cc	(revision 8)
@@ -0,0 +1,407 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include <hu/varadiistvan/scpl/io/Waiter.h>
+#include <hu/varadiistvan/scpl/io/LocalServerSocket.h>
+#include <hu/varadiistvan/scpl/io/LocalAcceptor.h>
+#include <hu/varadiistvan/scpl/io/LocalSocket.h>
+#include <hu/varadiistvan/scpl/io/LocalClientSocket.h>
+#include <hu/varadiistvan/scpl/io/LocalConnector.h>
+#include <hu/varadiistvan/scpl/io/ReadingBuffer.h>
+#include <hu/varadiistvan/scpl/io/WritingBuffer.h>
+#include <hu/varadiistvan/scpl/io/WaitableEvent.h>
+
+#include <hu/varadiistvan/scpl/Thread.h>
+#include <hu/varadiistvan/scpl/PseudoRandom.h>
+
+#include <cstdlib>
+#include <cstdio>
+#include <cassert>
+
+#include <signal.h>
+
+#include <sys/time.h>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::Waiter;
+using hu::varadiistvan::scpl::io::LocalServerSocket;
+using hu::varadiistvan::scpl::io::LocalAcceptor;
+using hu::varadiistvan::scpl::io::LocalSocket;
+using hu::varadiistvan::scpl::io::LocalClientSocket;
+using hu::varadiistvan::scpl::io::LocalConnector;
+using hu::varadiistvan::scpl::io::ReadingBuffer;
+using hu::varadiistvan::scpl::io::WritingBuffer;
+using hu::varadiistvan::scpl::io::WaitableEvent;
+
+using hu::varadiistvan::scpl::Thread;
+using hu::varadiistvan::scpl::PseudoRandom;
+
+using std::min;
+
+//------------------------------------------------------------------------------
+
+void communicate(ReadingBuffer* readingBuffer, WritingBuffer* writingBuffer,
+                 Waiter& waiter, unsigned seed, const char* prefix,
+                 WaitableEvent* quitEvent = 0)
+{
+    static const size_t minToWrite = 2076;
+    static const size_t maxToWrite = 1345670;
+
+    static const size_t reportingInterval = 10000;
+
+    static const int sleepThreshold = static_cast<int>(PseudoRandom::MAX * 0.99);
+    static const int sleepRemainder = PseudoRandom::MAX - sleepThreshold;
+    static const unsigned minSleep = 10;
+    static const unsigned maxSleep = 250;
+    static const unsigned sleepRange = maxSleep - minSleep;
+
+    size_t numBytesRead = 0;
+    size_t nextReportRead = reportingInterval;
+    size_t numWriteBlocked = 0;
+    size_t numBytesWritten = 0;
+    size_t nextReportWritten = reportingInterval;
+    size_t numReadBlocked = 0;
+    size_t numMillisSlept = 0;
+
+    bool toQuit = false;
+
+    PseudoRandom random(seed);
+    while(!toQuit) {
+        size_t toWrite = random.nextUnsigned(maxToWrite, minToWrite);
+
+        size_t lastWriteLength = 0;
+        if (writingBuffer!=0) {
+            lastWriteLength = min(writingBuffer->getCapacity(), toWrite);
+            writingBuffer->reset();
+            writingBuffer->addLength(lastWriteLength);
+        }
+
+        while(toWrite>0) {
+            if (quitEvent!=0 && quitEvent->check()) {
+                toQuit = true;
+                break;
+            }
+
+            bool hasPending = false;
+
+            if (writingBuffer!=0) {
+                size_t loopCount = 0;
+                while(toWrite>0) {
+                    ++loopCount;
+                    if (writingBuffer->write()) {
+                        numBytesWritten += lastWriteLength;
+                        toWrite -= lastWriteLength;
+
+                        if (numBytesWritten>=nextReportWritten) {
+                            printf("%s: written %lu bytes with %lu blocking and %lu ms sleeping\n",
+                                   prefix,
+                                   static_cast<unsigned long>(numBytesWritten),
+                                   static_cast<unsigned long>(numWriteBlocked),
+                                   static_cast<unsigned long>(numMillisSlept));
+                            nextReportWritten += reportingInterval;
+                        }
+
+                        if (toWrite>0) {
+                            if (quitEvent!=0 && quitEvent->check()) {
+                                toQuit = true;
+                                break;
+                            } else {
+                                lastWriteLength = min(writingBuffer->getCapacity(), toWrite);
+                                writingBuffer->addLength(lastWriteLength);
+                                if (loopCount>10) {
+                                    break;
+                                }
+                            }
+                        }
+                    } else if (writingBuffer->failed()) {
+                        printf("%s: writing failed with error: %lu\n",
+                               prefix,
+                               static_cast<unsigned long>(writingBuffer->getErrorCode()));
+                        toQuit = true;
+                        break;
+                    } else {
+                        ++numWriteBlocked;
+                        hasPending = true;
+                        break;
+                    }
+                }
+                if (toQuit) break;
+            }
+
+            if (readingBuffer!=0) {
+                size_t loopCount = 0;
+                while(true) {
+                    ++loopCount;
+                    if (readingBuffer->read()) {
+                        size_t l = readingBuffer->getLength();
+                        if (l==0) {
+                            printf("%s: reading encountered end of file\n", prefix);
+                            toQuit = true;
+                            break;
+                        }
+                        numBytesRead += l;
+                        if (numBytesRead>=nextReportRead) {
+                            printf("%s: read %lu bytes with %lu blocking and %lu ms sleeping\n",
+                                   prefix,
+                                   static_cast<unsigned long>(numBytesRead),
+                                   static_cast<unsigned long>(numReadBlocked),
+                                   static_cast<unsigned long>(numMillisSlept));
+                            nextReportRead += reportingInterval;
+                        }
+                        readingBuffer->reset();
+                        if (quitEvent!=0 && quitEvent->check()) {
+                            toQuit = true;
+                            break;
+                        } else if (loopCount>10) {
+                            break;
+                        }
+                    } else if (readingBuffer->failed()) {
+                        printf("%s: reading failed with error: %lu\n",
+                               prefix,
+                               static_cast<unsigned long>(readingBuffer->getErrorCode()));
+                        toQuit = true;
+                        break;
+                    } else {
+                        ++numReadBlocked;
+                        hasPending = true;
+                        break;
+                    }
+                }
+                if (toQuit) break;
+            }
+
+            int r = random.next();
+            if (r>=sleepThreshold) {
+                unsigned toSleep = minSleep +
+                    static_cast<unsigned>(static_cast<double>(r - sleepThreshold) *
+                                          sleepRange / sleepRemainder);
+                assert(toSleep>=minSleep);
+                assert(toSleep<maxSleep);
+                Thread::sleep(toSleep);
+                numMillisSlept += toSleep;
+            }
+
+            if (toWrite>0 && hasPending) {
+                waiter.wait();
+                if (waiter.failed()) {
+                    printf("%s: waiting failed with error: %lu\n",
+                           prefix,
+                           static_cast<unsigned long>(waiter.getErrorCode()));
+                    toQuit = true;
+                    break;
+                }
+            }
+        }
+    }
+
+    printf("%s: written %lu bytes with %lu blocking\n",
+           prefix,
+           static_cast<unsigned long>(numBytesWritten),
+           static_cast<unsigned long>(numWriteBlocked));
+    printf("%s: read %lu bytes with %lu blocking\n",
+           prefix,
+           static_cast<unsigned long>(numBytesRead),
+           static_cast<unsigned long>(numReadBlocked));
+    printf("%s: slept %lu ms\n", prefix,
+           static_cast<unsigned long>(numMillisSlept));
+}
+
+//------------------------------------------------------------------------------
+
+class ServerThread : public Thread
+{
+private:
+    Waiter waiter;
+
+    WaitableEvent event;
+
+public:
+    ServerThread();
+
+    void signal();
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+ServerThread::ServerThread() :
+    event(&waiter)
+{
+}
+
+//------------------------------------------------------------------------------
+
+void ServerThread::signal()
+{
+    event.fire();
+}
+
+//------------------------------------------------------------------------------
+
+void ServerThread::run()
+{
+    unsigned seed = static_cast<unsigned>(time(0)*1.2);
+    printf("ServerThread::run: seed=%u\n", seed);
+
+    LocalServerSocket serverSocket("test", &waiter);
+    LocalAcceptor& acceptor = serverSocket.getAcceptor();
+
+    bool eventFired = false;
+    while(!acceptor.accept()) {
+        eventFired = event.check();
+        if (eventFired) break;
+        if (acceptor.failed()) {
+            printf("ServerThread::run: acceptor failed...: %lu\n",
+                   (unsigned long)acceptor.getErrorCode());
+            return;
+        }
+        printf("ServerThread::run: waiting...\n");
+        waiter.wait();
+    }
+
+    if (eventFired) {
+        printf("ServerThread::run: waiting done, quitting\n");
+        return;
+    }
+
+    printf("ServerThread::run: waiting done, received connection\n");
+    LocalSocket* socket = acceptor.getSocket();
+
+    communicate(&socket->getReadingBuffer(), &socket->getWritingBuffer(),
+                waiter, seed, "ServerThread", &event);
+
+
+    delete socket;
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class ClientThread : public Thread
+{
+private:
+    Waiter waiter;
+
+    WaitableEvent event;
+
+public:
+    ClientThread();
+
+    void signal();
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+ClientThread::ClientThread() :
+    event(&waiter)
+{
+}
+
+//------------------------------------------------------------------------------
+
+void ClientThread::signal()
+{
+    event.fire();
+}
+
+//------------------------------------------------------------------------------
+
+void ClientThread::run()
+{
+    unsigned seed = static_cast<unsigned>(time(0)*1.8);
+    printf("ClientThread::run: seed=%u\n", seed);
+
+    printf("ClientThread::run: sleeping\n");
+    sleep(500);
+    printf("ClientThread::run: connecting\n");
+
+    LocalClientSocket socket("test", &waiter);
+
+    LocalConnector& connector = socket.getConnector();
+
+    while(!connector.connect()) {
+        if (connector.failed()) {
+            printf("ClientThread::run: connector failed...\n");
+            return;
+        }
+        printf("ClientThread::run: waiting...\n");
+        waiter.wait();
+    }
+
+    printf("ClientThread::run: connected\n");
+
+    communicate(&socket.getReadingBuffer(), &socket.getWritingBuffer(),
+                waiter, seed, "ClientThread", &event);
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+int main()
+{
+#if TARGET_API_POSIX
+    signal(SIGPIPE, SIG_IGN);
+#endif
+
+    ServerThread serverThread;
+    ClientThread clientThread;
+
+    printf("Starting threads\n");
+    serverThread.start();
+    clientThread.start();
+
+    Thread::sleep(60000);
+    //Thread::sleep(5000);
+    printf("Signalling the server thread\n");
+    //serverThread.signal();
+    clientThread.signal();
+    printf("Signalled the server thread\n");
+
+    printf("Waiting for the client thread\n");
+    clientThread.join();
+    printf("Waiting for the server thread\n");
+    serverThread.join();
+    printf("Both threads returned\n");
+
+    return 0;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: test/testlocsock.cc
===================================================================
--- test/testlocsock.cc	(revision 8)
+++ 	(revision )
@@ -1,407 +1,0 @@
-// Copyright (c) 2012 by István Váradi
-
-// This file is part of libxplcommon, a common utility library for
-// development related to X-Plane
-
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-
-// 1. Redistributions of source code must retain the above copyright notice, this
-//    list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-//    this list of conditions and the following disclaimer in the documentation
-//    and/or other materials provided with the distribution.
-
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// The views and conclusions contained in the software and documentation are those
-// of the authors and should not be interpreted as representing official policies,
-// either expressed or implied, of the FreeBSD Project.
-
-//------------------------------------------------------------------------------
-
-#include <hu/varadiistvan/scpl/io/Waiter.h>
-#include <hu/varadiistvan/scpl/io/LocalServerSocket.h>
-#include <hu/varadiistvan/scpl/io/LocalAcceptor.h>
-#include <hu/varadiistvan/scpl/io/LocalSocket.h>
-#include <hu/varadiistvan/scpl/io/LocalClientSocket.h>
-#include <hu/varadiistvan/scpl/io/LocalConnector.h>
-#include <hu/varadiistvan/scpl/io/ReadingBuffer.h>
-#include <hu/varadiistvan/scpl/io/WritingBuffer.h>
-#include <hu/varadiistvan/scpl/io/WaitableEvent.h>
-
-#include <hu/varadiistvan/scpl/Thread.h>
-#include <hu/varadiistvan/scpl/PseudoRandom.h>
-
-#include <cstdlib>
-#include <cstdio>
-#include <cassert>
-
-#include <signal.h>
-
-#include <sys/time.h>
-
-//------------------------------------------------------------------------------
-
-using hu::varadiistvan::scpl::io::Waiter;
-using hu::varadiistvan::scpl::io::LocalServerSocket;
-using hu::varadiistvan::scpl::io::LocalAcceptor;
-using hu::varadiistvan::scpl::io::LocalSocket;
-using hu::varadiistvan::scpl::io::LocalClientSocket;
-using hu::varadiistvan::scpl::io::LocalConnector;
-using hu::varadiistvan::scpl::io::ReadingBuffer;
-using hu::varadiistvan::scpl::io::WritingBuffer;
-using hu::varadiistvan::scpl::io::WaitableEvent;
-
-using hu::varadiistvan::scpl::Thread;
-using hu::varadiistvan::scpl::PseudoRandom;
-
-using std::min;
-
-//------------------------------------------------------------------------------
-
-void communicate(ReadingBuffer* readingBuffer, WritingBuffer* writingBuffer,
-                 Waiter& waiter, unsigned seed, const char* prefix,
-                 WaitableEvent* quitEvent = 0)
-{
-    static const size_t minToWrite = 2076;
-    static const size_t maxToWrite = 1345670;
-
-    static const size_t reportingInterval = 10000;
-
-    static const int sleepThreshold = static_cast<int>(PseudoRandom::MAX * 0.99);
-    static const int sleepRemainder = PseudoRandom::MAX - sleepThreshold;
-    static const unsigned minSleep = 10;
-    static const unsigned maxSleep = 250;
-    static const unsigned sleepRange = maxSleep - minSleep;
-
-    size_t numBytesRead = 0;
-    size_t nextReportRead = reportingInterval;
-    size_t numWriteBlocked = 0;
-    size_t numBytesWritten = 0;
-    size_t nextReportWritten = reportingInterval;
-    size_t numReadBlocked = 0;
-    size_t numMillisSlept = 0;
-
-    bool toQuit = false;
-
-    PseudoRandom random(seed);
-    while(!toQuit) {
-        size_t toWrite = random.nextUnsigned(maxToWrite, minToWrite);
-
-        size_t lastWriteLength = 0;
-        if (writingBuffer!=0) {
-            lastWriteLength = min(writingBuffer->getCapacity(), toWrite);
-            writingBuffer->reset();
-            writingBuffer->addLength(lastWriteLength);
-        }
-
-        while(toWrite>0) {
-            if (quitEvent!=0 && quitEvent->check()) {
-                toQuit = true;
-                break;
-            }
-
-            bool hasPending = false;
-
-            if (writingBuffer!=0) {
-                size_t loopCount = 0;
-                while(toWrite>0) {
-                    ++loopCount;
-                    if (writingBuffer->write()) {
-                        numBytesWritten += lastWriteLength;
-                        toWrite -= lastWriteLength;
-
-                        if (numBytesWritten>=nextReportWritten) {
-                            printf("%s: written %lu bytes with %lu blocking and %lu ms sleeping\n",
-                                   prefix,
-                                   static_cast<unsigned long>(numBytesWritten),
-                                   static_cast<unsigned long>(numWriteBlocked),
-                                   static_cast<unsigned long>(numMillisSlept));
-                            nextReportWritten += reportingInterval;
-                        }
-
-                        if (toWrite>0) {
-                            if (quitEvent!=0 && quitEvent->check()) {
-                                toQuit = true;
-                                break;
-                            } else {
-                                lastWriteLength = min(writingBuffer->getCapacity(), toWrite);
-                                writingBuffer->addLength(lastWriteLength);
-                                if (loopCount>10) {
-                                    break;
-                                }
-                            }
-                        }
-                    } else if (writingBuffer->failed()) {
-                        printf("%s: writing failed with error: %lu\n",
-                               prefix,
-                               static_cast<unsigned long>(writingBuffer->getErrorCode()));
-                        toQuit = true;
-                        break;
-                    } else {
-                        ++numWriteBlocked;
-                        hasPending = true;
-                        break;
-                    }
-                }
-                if (toQuit) break;
-            }
-
-            if (readingBuffer!=0) {
-                size_t loopCount = 0;
-                while(true) {
-                    ++loopCount;
-                    if (readingBuffer->read()) {
-                        size_t l = readingBuffer->getLength();
-                        if (l==0) {
-                            printf("%s: reading encountered end of file\n", prefix);
-                            toQuit = true;
-                            break;
-                        }
-                        numBytesRead += l;
-                        if (numBytesRead>=nextReportRead) {
-                            printf("%s: read %lu bytes with %lu blocking and %lu ms sleeping\n",
-                                   prefix,
-                                   static_cast<unsigned long>(numBytesRead),
-                                   static_cast<unsigned long>(numReadBlocked),
-                                   static_cast<unsigned long>(numMillisSlept));
-                            nextReportRead += reportingInterval;
-                        }
-                        readingBuffer->reset();
-                        if (quitEvent!=0 && quitEvent->check()) {
-                            toQuit = true;
-                            break;
-                        } else if (loopCount>10) {
-                            break;
-                        }
-                    } else if (readingBuffer->failed()) {
-                        printf("%s: reading failed with error: %lu\n",
-                               prefix,
-                               static_cast<unsigned long>(readingBuffer->getErrorCode()));
-                        toQuit = true;
-                        break;
-                    } else {
-                        ++numReadBlocked;
-                        hasPending = true;
-                        break;
-                    }
-                }
-                if (toQuit) break;
-            }
-
-            int r = random.next();
-            if (r>=sleepThreshold) {
-                unsigned toSleep = minSleep +
-                    static_cast<unsigned>(static_cast<double>(r - sleepThreshold) *
-                                          sleepRange / sleepRemainder);
-                assert(toSleep>=minSleep);
-                assert(toSleep<maxSleep);
-                Thread::sleep(toSleep);
-                numMillisSlept += toSleep;
-            }
-
-            if (toWrite>0 && hasPending) {
-                waiter.wait();
-                if (waiter.failed()) {
-                    printf("%s: waiting failed with error: %lu\n",
-                           prefix,
-                           static_cast<unsigned long>(waiter.getErrorCode()));
-                    toQuit = true;
-                    break;
-                }
-            }
-        }
-    }
-
-    printf("%s: written %lu bytes with %lu blocking\n",
-           prefix,
-           static_cast<unsigned long>(numBytesWritten),
-           static_cast<unsigned long>(numWriteBlocked));
-    printf("%s: read %lu bytes with %lu blocking\n",
-           prefix,
-           static_cast<unsigned long>(numBytesRead),
-           static_cast<unsigned long>(numReadBlocked));
-    printf("%s: slept %lu ms\n", prefix,
-           static_cast<unsigned long>(numMillisSlept));
-}
-
-//------------------------------------------------------------------------------
-
-class ServerThread : public Thread
-{
-private:
-    Waiter waiter;
-
-    WaitableEvent event;
-
-public:
-    ServerThread();
-
-    void signal();
-
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-ServerThread::ServerThread() :
-    event(&waiter)
-{
-}
-
-//------------------------------------------------------------------------------
-
-void ServerThread::signal()
-{
-    event.fire();
-}
-
-//------------------------------------------------------------------------------
-
-void ServerThread::run()
-{
-    unsigned seed = static_cast<unsigned>(time(0)*1.2);
-    printf("ServerThread::run: seed=%u\n", seed);
-
-    LocalServerSocket serverSocket("test", &waiter);
-    LocalAcceptor& acceptor = serverSocket.getAcceptor();
-
-    bool eventFired = false;
-    while(!acceptor.accept()) {
-        eventFired = event.check();
-        if (eventFired) break;
-        if (acceptor.failed()) {
-            printf("ServerThread::run: acceptor failed...: %lu\n",
-                   (unsigned long)acceptor.getErrorCode());
-            return;
-        }
-        printf("ServerThread::run: waiting...\n");
-        waiter.wait();
-    }
-
-    if (eventFired) {
-        printf("ServerThread::run: waiting done, quitting\n");
-        return;
-    }
-
-    printf("ServerThread::run: waiting done, received connection\n");
-    LocalSocket* socket = acceptor.getSocket();
-
-    communicate(&socket->getReadingBuffer(), &socket->getWritingBuffer(),
-                waiter, seed, "ServerThread", &event);
-
-
-    delete socket;
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-class ClientThread : public Thread
-{
-private:
-    Waiter waiter;
-
-    WaitableEvent event;
-
-public:
-    ClientThread();
-
-    void signal();
-
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-ClientThread::ClientThread() :
-    event(&waiter)
-{
-}
-
-//------------------------------------------------------------------------------
-
-void ClientThread::signal()
-{
-    event.fire();
-}
-
-//------------------------------------------------------------------------------
-
-void ClientThread::run()
-{
-    unsigned seed = static_cast<unsigned>(time(0)*1.8);
-    printf("ClientThread::run: seed=%u\n", seed);
-
-    printf("ClientThread::run: sleeping\n");
-    sleep(500);
-    printf("ClientThread::run: connecting\n");
-
-    LocalClientSocket socket("test", &waiter);
-
-    LocalConnector& connector = socket.getConnector();
-
-    while(!connector.connect()) {
-        if (connector.failed()) {
-            printf("ClientThread::run: connector failed...\n");
-            return;
-        }
-        printf("ClientThread::run: waiting...\n");
-        waiter.wait();
-    }
-
-    printf("ClientThread::run: connected\n");
-
-    communicate(&socket.getReadingBuffer(), &socket.getWritingBuffer(),
-                waiter, seed, "ClientThread", &event);
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-int main()
-{
-#if TARGET_API_POSIX
-    signal(SIGPIPE, SIG_IGN);
-#endif
-
-    ServerThread serverThread;
-    ClientThread clientThread;
-
-    printf("Starting threads\n");
-    serverThread.start();
-    clientThread.start();
-
-    Thread::sleep(60000);
-    //Thread::sleep(5000);
-    printf("Signalling the server thread\n");
-    //serverThread.signal();
-    clientThread.signal();
-    printf("Signalled the server thread\n");
-
-    printf("Waiting for the client thread\n");
-    clientThread.join();
-    printf("Waiting for the server thread\n");
-    serverThread.join();
-    printf("Both threads returned\n");
-
-    return 0;
-}
-
-//------------------------------------------------------------------------------
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: test/testmulticlient.cc
===================================================================
--- test/testmulticlient.cc	(revision 14)
+++ test/testmulticlient.cc	(revision 14)
@@ -0,0 +1,74 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of VSCPL, a simple cross-platform utility library
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include <hu/varadiistvan/scpl/io/Waiter.h>
+#include <hu/varadiistvan/scpl/io/LocalClientSocket.h>
+#include <hu/varadiistvan/scpl/io/LocalConnector.h>
+#include <hu/varadiistvan/scpl/io/DataStream.h>
+
+#include <hu/varadiistvan/scpl/Thread.h>
+
+#include <cstdio>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::Waiter;
+using hu::varadiistvan::scpl::io::LocalClientSocket;
+using hu::varadiistvan::scpl::io::LocalConnector;
+using hu::varadiistvan::scpl::io::DataStream;
+
+using hu::varadiistvan::scpl::Thread;
+
+//------------------------------------------------------------------------------
+
+int main()
+{
+    Waiter waiter;
+
+    LocalClientSocket socket1("testmc", &waiter);
+    LocalConnector& connector1 = socket1.getConnector();
+    printf("Connecting...\n");
+    connector1.connect();
+    printf("Connected...\n");
+    DataStream stream1(socket1);
+
+    stream1.writeU8(0x02);
+    stream1.flush();
+
+    Thread::sleep(5000);
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: test/testmulticlient.cc
===================================================================
--- test/testmulticlient.cc	(revision 14)
+++ 	(revision )
@@ -1,74 +1,0 @@
-// Copyright (c) 2013 by István Váradi
-
-// This file is part of VSCPL, a simple cross-platform utility library
-
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-
-// 1. Redistributions of source code must retain the above copyright notice, this
-//    list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-//    this list of conditions and the following disclaimer in the documentation
-//    and/or other materials provided with the distribution.
-
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// The views and conclusions contained in the software and documentation are those
-// of the authors and should not be interpreted as representing official policies,
-// either expressed or implied, of the FreeBSD Project.
-
-//------------------------------------------------------------------------------
-
-#include <hu/varadiistvan/scpl/io/Waiter.h>
-#include <hu/varadiistvan/scpl/io/LocalClientSocket.h>
-#include <hu/varadiistvan/scpl/io/LocalConnector.h>
-#include <hu/varadiistvan/scpl/io/DataStream.h>
-
-#include <hu/varadiistvan/scpl/Thread.h>
-
-#include <cstdio>
-
-//------------------------------------------------------------------------------
-
-using hu::varadiistvan::scpl::io::Waiter;
-using hu::varadiistvan::scpl::io::LocalClientSocket;
-using hu::varadiistvan::scpl::io::LocalConnector;
-using hu::varadiistvan::scpl::io::DataStream;
-
-using hu::varadiistvan::scpl::Thread;
-
-//------------------------------------------------------------------------------
-
-int main()
-{
-    Waiter waiter;
-
-    LocalClientSocket socket1("testmc", &waiter);
-    LocalConnector& connector1 = socket1.getConnector();
-    printf("Connecting...\n");
-    connector1.connect();
-    printf("Connected...\n");
-    DataStream stream1(socket1);
-
-    stream1.writeU8(0x02);
-    stream1.flush();
-
-    Thread::sleep(5000);
-}
-
-//------------------------------------------------------------------------------
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: test/testmultiserver.cc
===================================================================
--- test/testmultiserver.cc	(revision 14)
+++ test/testmultiserver.cc	(revision 14)
@@ -0,0 +1,140 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of VSCPL, a simple cross-platform utility library
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include <hu/varadiistvan/scpl/io/Waiter.h>
+#include <hu/varadiistvan/scpl/io/LocalServerSocket.h>
+#include <hu/varadiistvan/scpl/io/LocalAcceptor.h>
+#include <hu/varadiistvan/scpl/io/BufferedStream.h>
+#include <hu/varadiistvan/scpl/io/DataStream.h>
+
+#include <hu/varadiistvan/scpl/Thread.h>
+
+#include <cstdio>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::Waiter;
+using hu::varadiistvan::scpl::io::LocalServerSocket;
+using hu::varadiistvan::scpl::io::LocalAcceptor;
+using hu::varadiistvan::scpl::io::BufferedStream;
+using hu::varadiistvan::scpl::io::DataStream;
+
+using hu::varadiistvan::scpl::Thread;
+
+//------------------------------------------------------------------------------
+
+class ServerThread : public Thread
+{
+    hu::varadiistvan::scpl::io::Waiter waiter;
+
+    hu::varadiistvan::scpl::io::BufferedStream* bufferedStream;
+
+    hu::varadiistvan::scpl::io::DataStream stream;
+
+public:
+    ServerThread(hu::varadiistvan::scpl::io::LocalAcceptor& acceptor);
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+ServerThread::ServerThread(LocalAcceptor& acceptor) :
+    bufferedStream(acceptor.getSocket(&waiter)),
+    stream(*bufferedStream)
+{
+    printf("Created ServerThread[%p]\n", this);
+}
+
+//------------------------------------------------------------------------------
+
+void ServerThread::run()
+{
+    while(stream) {
+        uint8_t value = stream.readU8();
+        if (!stream) continue;
+
+        printf("ServerThread[%p]: value=0x%02x\n", this, value);
+    }
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class ListenThread : public Thread
+{
+public:
+    virtual void run();
+};
+
+
+//------------------------------------------------------------------------------
+
+void ListenThread::run()
+{
+    printf("ListenThread::run\n");
+
+    Waiter waiter;
+
+    LocalServerSocket socket("testmc", &waiter);
+
+    LocalAcceptor& acceptor = socket.getAcceptor();
+    while(!acceptor.failed()) {
+        printf("ListenThread::run: accepting...\n");
+        while (acceptor.accept()) {
+            printf("ListenThread::run: connection accepted\n");
+            ServerThread* serverThread = new ServerThread(acceptor);
+            serverThread->start();
+        }
+        printf("ListenThread::run: waiting...\n");
+        waiter.wait();
+        printf("ListenThread::run: waited...\n");
+    }
+}
+
+//------------------------------------------------------------------------------
+
+int main()
+{
+    ListenThread listenThread;
+    listenThread.start();
+
+    while(true) {
+        Thread::sleep(3600*1000);
+    };
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: test/testmultiserver.cc
===================================================================
--- test/testmultiserver.cc	(revision 14)
+++ 	(revision )
@@ -1,140 +1,0 @@
-// Copyright (c) 2013 by István Váradi
-
-// This file is part of VSCPL, a simple cross-platform utility library
-
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-
-// 1. Redistributions of source code must retain the above copyright notice, this
-//    list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-//    this list of conditions and the following disclaimer in the documentation
-//    and/or other materials provided with the distribution.
-
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// The views and conclusions contained in the software and documentation are those
-// of the authors and should not be interpreted as representing official policies,
-// either expressed or implied, of the FreeBSD Project.
-
-//------------------------------------------------------------------------------
-
-#include <hu/varadiistvan/scpl/io/Waiter.h>
-#include <hu/varadiistvan/scpl/io/LocalServerSocket.h>
-#include <hu/varadiistvan/scpl/io/LocalAcceptor.h>
-#include <hu/varadiistvan/scpl/io/BufferedStream.h>
-#include <hu/varadiistvan/scpl/io/DataStream.h>
-
-#include <hu/varadiistvan/scpl/Thread.h>
-
-#include <cstdio>
-
-//------------------------------------------------------------------------------
-
-using hu::varadiistvan::scpl::io::Waiter;
-using hu::varadiistvan::scpl::io::LocalServerSocket;
-using hu::varadiistvan::scpl::io::LocalAcceptor;
-using hu::varadiistvan::scpl::io::BufferedStream;
-using hu::varadiistvan::scpl::io::DataStream;
-
-using hu::varadiistvan::scpl::Thread;
-
-//------------------------------------------------------------------------------
-
-class ServerThread : public Thread
-{
-    hu::varadiistvan::scpl::io::Waiter waiter;
-
-    hu::varadiistvan::scpl::io::BufferedStream* bufferedStream;
-
-    hu::varadiistvan::scpl::io::DataStream stream;
-
-public:
-    ServerThread(hu::varadiistvan::scpl::io::LocalAcceptor& acceptor);
-
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-ServerThread::ServerThread(LocalAcceptor& acceptor) :
-    bufferedStream(acceptor.getSocket(&waiter)),
-    stream(*bufferedStream)
-{
-    printf("Created ServerThread[%p]\n", this);
-}
-
-//------------------------------------------------------------------------------
-
-void ServerThread::run()
-{
-    while(stream) {
-        uint8_t value = stream.readU8();
-        if (!stream) continue;
-
-        printf("ServerThread[%p]: value=0x%02x\n", this, value);
-    }
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-class ListenThread : public Thread
-{
-public:
-    virtual void run();
-};
-
-
-//------------------------------------------------------------------------------
-
-void ListenThread::run()
-{
-    printf("ListenThread::run\n");
-
-    Waiter waiter;
-
-    LocalServerSocket socket("testmc", &waiter);
-
-    LocalAcceptor& acceptor = socket.getAcceptor();
-    while(!acceptor.failed()) {
-        printf("ListenThread::run: accepting...\n");
-        while (acceptor.accept()) {
-            printf("ListenThread::run: connection accepted\n");
-            ServerThread* serverThread = new ServerThread(acceptor);
-            serverThread->start();
-        }
-        printf("ListenThread::run: waiting...\n");
-        waiter.wait();
-        printf("ListenThread::run: waited...\n");
-    }
-}
-
-//------------------------------------------------------------------------------
-
-int main()
-{
-    ListenThread listenThread;
-    listenThread.start();
-
-    while(true) {
-        Thread::sleep(3600*1000);
-    };
-}
-
-//------------------------------------------------------------------------------
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: test/testmutex.cc
===================================================================
--- test/testmutex.cc	(revision 4)
+++ test/testmutex.cc	(revision 4)
@@ -0,0 +1,162 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of VSCPL, a simple cross-platform utility library
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include <hu/varadiistvan/scpl/Thread.h>
+#include <hu/varadiistvan/scpl/Mutex.h>
+
+#include <cstdlib>
+#include <cstdio>
+#include <cassert>
+
+#include <signal.h>
+
+#include <sys/time.h>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::Thread;
+using hu::varadiistvan::scpl::Mutex;
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class Thread1 : public Thread
+{
+private:
+    Mutex& mutex;
+
+public:
+    Thread1(Mutex& mutex);
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+inline Thread1::Thread1(Mutex& mutex) :
+    mutex(mutex)
+{
+}
+
+//------------------------------------------------------------------------------
+
+void Thread1::run()
+{
+    printf("Thread1::run: locking mutex\n");
+    mutex.lock();
+    printf("Thread1::run: locked mutex, sleeping...\n");
+
+    sleep(5000);
+
+    printf("Thread1::run: woke up, releasing mutex\n");
+    mutex.unlock();
+
+    printf("Thread1::run: released mutex, sleeping\n");
+
+    sleep(1000);
+
+    printf("Thread1::run: woke up, locking mutex\n");
+    mutex.lock();
+    printf("Thread1::run: locked mutex, releasing\n");
+    mutex.unlock();
+
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+class Thread2 : public Thread
+{
+private:
+    Mutex& mutex;
+
+public:
+    Thread2(Mutex& mutex);
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+inline Thread2::Thread2(Mutex& mutex) :
+    mutex(mutex)
+{
+}
+
+//------------------------------------------------------------------------------
+
+void Thread2::run()
+{
+    printf("Thread2::run: sleeping\n");
+    sleep(1000);
+
+    printf("Thread2::run: woke up, trying to lock mutex...\n");
+
+    while(!mutex.tryLock()) {
+        sleep(200);
+    }
+
+    printf("Thread2::run: locked mutex, sleeping...\n");
+    sleep(5000);
+    printf("Thread2::run: woke up, releasing mutex\n");
+    mutex.unlock();
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+int main()
+{
+    Mutex mutex;
+
+    Thread1 thread1(mutex);
+    Thread2 thread2(mutex);
+
+    printf("Starting threads\n");
+    thread1.start();
+    thread2.start();
+
+
+    printf("Waiting for thread1\n");
+    thread1.join();
+    printf("Waiting for thread2\n");
+    thread2.join();
+    printf("Both threads returned\n");
+
+    return 0;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: test/testmutex.cc
===================================================================
--- test/testmutex.cc	(revision 4)
+++ 	(revision )
@@ -1,162 +1,0 @@
-// Copyright (c) 2012 by István Váradi
-
-// This file is part of VSCPL, a simple cross-platform utility library
-
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-
-// 1. Redistributions of source code must retain the above copyright notice, this
-//    list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-//    this list of conditions and the following disclaimer in the documentation
-//    and/or other materials provided with the distribution.
-
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// The views and conclusions contained in the software and documentation are those
-// of the authors and should not be interpreted as representing official policies,
-// either expressed or implied, of the FreeBSD Project.
-
-//------------------------------------------------------------------------------
-
-#include <hu/varadiistvan/scpl/Thread.h>
-#include <hu/varadiistvan/scpl/Mutex.h>
-
-#include <cstdlib>
-#include <cstdio>
-#include <cassert>
-
-#include <signal.h>
-
-#include <sys/time.h>
-
-//------------------------------------------------------------------------------
-
-using hu::varadiistvan::scpl::Thread;
-using hu::varadiistvan::scpl::Mutex;
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-class Thread1 : public Thread
-{
-private:
-    Mutex& mutex;
-
-public:
-    Thread1(Mutex& mutex);
-
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-inline Thread1::Thread1(Mutex& mutex) :
-    mutex(mutex)
-{
-}
-
-//------------------------------------------------------------------------------
-
-void Thread1::run()
-{
-    printf("Thread1::run: locking mutex\n");
-    mutex.lock();
-    printf("Thread1::run: locked mutex, sleeping...\n");
-
-    sleep(5000);
-
-    printf("Thread1::run: woke up, releasing mutex\n");
-    mutex.unlock();
-
-    printf("Thread1::run: released mutex, sleeping\n");
-
-    sleep(1000);
-
-    printf("Thread1::run: woke up, locking mutex\n");
-    mutex.lock();
-    printf("Thread1::run: locked mutex, releasing\n");
-    mutex.unlock();
-
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-class Thread2 : public Thread
-{
-private:
-    Mutex& mutex;
-
-public:
-    Thread2(Mutex& mutex);
-
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-inline Thread2::Thread2(Mutex& mutex) :
-    mutex(mutex)
-{
-}
-
-//------------------------------------------------------------------------------
-
-void Thread2::run()
-{
-    printf("Thread2::run: sleeping\n");
-    sleep(1000);
-
-    printf("Thread2::run: woke up, trying to lock mutex...\n");
-
-    while(!mutex.tryLock()) {
-        sleep(200);
-    }
-
-    printf("Thread2::run: locked mutex, sleeping...\n");
-    sleep(5000);
-    printf("Thread2::run: woke up, releasing mutex\n");
-    mutex.unlock();
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-int main()
-{
-    Mutex mutex;
-
-    Thread1 thread1(mutex);
-    Thread2 thread2(mutex);
-
-    printf("Starting threads\n");
-    thread1.start();
-    thread2.start();
-
-
-    printf("Waiting for thread1\n");
-    thread1.join();
-    printf("Waiting for thread2\n");
-    thread2.join();
-    printf("Both threads returned\n");
-
-    return 0;
-}
-
-//------------------------------------------------------------------------------
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: test/testrandom.cc
===================================================================
--- test/testrandom.cc	(revision 11)
+++ test/testrandom.cc	(revision 11)
@@ -0,0 +1,69 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include <hu/varadiistvan/scpl/PseudoRandom.h>
+
+#include <cstdio>
+#include <ctime>
+#include <cstdlib>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::PseudoRandom;
+
+//------------------------------------------------------------------------------
+
+int main(int argc, char* argv[])
+{
+    unsigned int seed = (argc>1) ? atoi(argv[1]) : time(0);
+
+    printf("seed=%u\n", seed);
+
+    srand(seed);
+    PseudoRandom pr(seed);
+    for(size_t i = 0; i<10000; ++i) {
+        int r1 = rand();
+        int r2 = pr.next();
+        if (r1!=r2) {
+            printf("values at i=%zu differ: rand(): %d, PseudoRandom: %d\n",
+                   i, r1, r2);
+            break;
+        }
+    }
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: test/testrandom.cc
===================================================================
--- test/testrandom.cc	(revision 11)
+++ 	(revision )
@@ -1,69 +1,0 @@
-// Copyright (c) 2013 by István Váradi
-
-// This file is part of libxplcommon, a common utility library for
-// development related to X-Plane
-
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-
-// 1. Redistributions of source code must retain the above copyright notice, this
-//    list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-//    this list of conditions and the following disclaimer in the documentation
-//    and/or other materials provided with the distribution.
-
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// The views and conclusions contained in the software and documentation are those
-// of the authors and should not be interpreted as representing official policies,
-// either expressed or implied, of the FreeBSD Project.
-
-//------------------------------------------------------------------------------
-
-#include <hu/varadiistvan/scpl/PseudoRandom.h>
-
-#include <cstdio>
-#include <ctime>
-#include <cstdlib>
-
-//------------------------------------------------------------------------------
-
-using hu::varadiistvan::scpl::PseudoRandom;
-
-//------------------------------------------------------------------------------
-
-int main(int argc, char* argv[])
-{
-    unsigned int seed = (argc>1) ? atoi(argv[1]) : time(0);
-
-    printf("seed=%u\n", seed);
-
-    srand(seed);
-    PseudoRandom pr(seed);
-    for(size_t i = 0; i<10000; ++i) {
-        int r1 = rand();
-        int r2 = pr.next();
-        if (r1!=r2) {
-            printf("values at i=%zu differ: rand(): %d, PseudoRandom: %d\n",
-                   i, r1, r2);
-            break;
-        }
-    }
-}
-
-//------------------------------------------------------------------------------
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
Index: test/testthread.cc
===================================================================
--- test/testthread.cc	(revision 2)
+++ test/testthread.cc	(revision 2)
@@ -0,0 +1,103 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of VSCPL, a simple cross-platform utility library
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include <hu/varadiistvan/scpl/Thread.h>
+
+#include <algorithm>
+
+#include <cstdio>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::Thread;
+
+using std::min;
+
+//------------------------------------------------------------------------------
+
+class TestThread : public Thread
+{
+private:
+    unsigned long id;
+
+public:
+    TestThread(unsigned long id);
+
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+inline TestThread::TestThread(unsigned long id) :
+    Thread(true),
+    id(id)
+{
+}
+
+//------------------------------------------------------------------------------
+
+void TestThread::run()
+{
+    printf("TestThread: id=%lu\n", id);
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+int main()
+{
+    static const size_t numThreads = 1000;
+
+    TestThread** threads = new TestThread*[numThreads];
+
+    unsigned long id = 1;
+    while(true) {
+        for(size_t i = 0; i<numThreads; ++i) {
+            threads[i] = new TestThread(id++);
+            threads[i]->start();
+        }
+
+        Thread::sleep(2000);
+
+        // for(size_t i = 0; i<numThreads; ++i) {
+        //     delete threads[i];
+        // }
+    }
+
+    return 0;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: test/testthread.cc
===================================================================
--- test/testthread.cc	(revision 2)
+++ 	(revision )
@@ -1,103 +1,0 @@
-// Copyright (c) 2013 by István Váradi
-
-// This file is part of VSCPL, a simple cross-platform utility library
-
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-
-// 1. Redistributions of source code must retain the above copyright notice, this
-//    list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-//    this list of conditions and the following disclaimer in the documentation
-//    and/or other materials provided with the distribution.
-
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// The views and conclusions contained in the software and documentation are those
-// of the authors and should not be interpreted as representing official policies,
-// either expressed or implied, of the FreeBSD Project.
-
-//------------------------------------------------------------------------------
-
-#include <hu/varadiistvan/scpl/Thread.h>
-
-#include <algorithm>
-
-#include <cstdio>
-
-//------------------------------------------------------------------------------
-
-using hu::varadiistvan::scpl::Thread;
-
-using std::min;
-
-//------------------------------------------------------------------------------
-
-class TestThread : public Thread
-{
-private:
-    unsigned long id;
-
-public:
-    TestThread(unsigned long id);
-
-    virtual void run();
-};
-
-//------------------------------------------------------------------------------
-
-inline TestThread::TestThread(unsigned long id) :
-    Thread(true),
-    id(id)
-{
-}
-
-//------------------------------------------------------------------------------
-
-void TestThread::run()
-{
-    printf("TestThread: id=%lu\n", id);
-}
-
-//------------------------------------------------------------------------------
-//------------------------------------------------------------------------------
-
-int main()
-{
-    static const size_t numThreads = 1000;
-
-    TestThread** threads = new TestThread*[numThreads];
-
-    unsigned long id = 1;
-    while(true) {
-        for(size_t i = 0; i<numThreads; ++i) {
-            threads[i] = new TestThread(id++);
-            threads[i]->start();
-        }
-
-        Thread::sleep(2000);
-
-        // for(size_t i = 0; i<numThreads; ++i) {
-        //     delete threads[i];
-        // }
-    }
-
-    return 0;
-}
-
-//------------------------------------------------------------------------------
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 4
-// indent-tabs-mode: nil
-// End:
