Index: src/hu/varadiistvan/scpl/Makefile.am
===================================================================
--- src/hu/varadiistvan/scpl/Makefile.am	(revision 6)
+++ src/hu/varadiistvan/scpl/Makefile.am	(revision 8)
@@ -13,5 +13,5 @@
 
 libvscpl_la_SOURCES=\
-        dummy.cc
+        PseudoRandom.cc
 
 libvscpl_la_LIBADD=
@@ -33,3 +33,4 @@
         Thread.h                \
         Mutex.h                 \
-        CondVar.h
+        CondVar.h               \
+        PseudoRandom.h
Index: src/hu/varadiistvan/scpl/PseudoRandom.cc
===================================================================
--- src/hu/varadiistvan/scpl/PseudoRandom.cc	(revision 8)
+++ src/hu/varadiistvan/scpl/PseudoRandom.cc	(revision 8)
@@ -0,0 +1,65 @@
+// 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 "PseudoRandom.h"
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::PseudoRandom;
+
+//------------------------------------------------------------------------------
+
+void PseudoRandom::initialize(uint32_t seed)
+{
+    vector[0] = seed;
+    for(size_t i = 1; i<vectorSize-3; ++i) {
+        int32_t x = (static_cast<long long>(16807) *
+                     static_cast<long long>(vector[i-1])) % 2147483647;
+        if (x<0) x += 2147483647;
+        vector[i] = x;
+    }
+    for(size_t i = vectorSize - 3; i<vectorSize; ++i) {
+        vector[i] = vector[i-31];
+    }
+
+    nextIndex = 0;
+
+    for(size_t i = vectorSize; i<numDiscarded; ++i) {
+        next();
+    }
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/PseudoRandom.h
===================================================================
--- src/hu/varadiistvan/scpl/PseudoRandom.h	(revision 8)
+++ src/hu/varadiistvan/scpl/PseudoRandom.h	(revision 8)
@@ -0,0 +1,174 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_PSEUDORANDOM_H
+#define HU_VARADIISTVAN_SCPL_PSEUDORANDOM_H
+//------------------------------------------------------------------------------
+
+#include <cstdlib>
+#include <ctime>
+
+#include <inttypes.h>
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A pseudo-random number generator. The algorithm is the same as
+ * described in http://www.mathstat.dal.ca/~selinger/random, i.e. the
+ * GNU libc random number generator. It is reimplemented, because
+ * Windows does not provide a thread-safe, reentrable pseudo-random
+ * number generation facility, so it should have been implemented for
+ * Win32 anyway.
+ */
+class PseudoRandom
+{
+public:
+    /**
+     * The largest random number generated in the unconverted
+     * sequence.
+     */
+    static const uint32_t MAX = (1<<31);
+
+private:
+    /**
+     * The size of the vector.
+     */
+    static const size_t vectorSize = 34;
+
+    /**
+     * The number of random numbers thrown away.
+     */
+    static const size_t numDiscarded = 344;
+
+    /**
+     * The vector of random numbers used to generate the next one.
+     */
+    uint32_t vector[vectorSize];
+
+    /**
+     * The index of the next random number.
+     */
+    int nextIndex;
+
+public:
+    /**
+     * Construct the random number generator with a default seed
+     * (taken by calling time()).
+     */
+    PseudoRandom();
+
+    /**
+     * Construct the random number generator with the given seed.
+     */
+    PseudoRandom(uint32_t seed);
+
+    /**
+     * Get the next raw value.
+     */
+    uint32_t next();
+
+    /**
+     * Get the next random number as an unsigned value between [from, to].
+     */
+    unsigned nextUnsigned(unsigned to = MAX, unsigned from=0);
+
+    /**
+     * Get the next random number as a double value between [from,
+     * to].
+     */
+    double nextDouble(double to = 1.0, double from= 0.0);
+
+private:
+    /**
+     * Initialize the random number generator with the given seed.
+     */
+    void initialize(uint32_t seed);
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline PseudoRandom::PseudoRandom()
+{
+    initialize(time(0));
+}
+
+//------------------------------------------------------------------------------
+
+inline PseudoRandom::PseudoRandom(uint32_t seed)
+{
+    initialize(seed);
+}
+
+//------------------------------------------------------------------------------
+
+inline uint32_t PseudoRandom::next()
+{
+    int i1 = (nextIndex<3) ? (vectorSize + nextIndex - 3) : (nextIndex - 3);
+    int i2 = (nextIndex<31) ? (vectorSize + nextIndex - 31) : (nextIndex - 31);
+
+    vector[nextIndex] = vector[i1] + vector[i2];
+    uint32_t x = vector[nextIndex]>>1;
+
+    ++nextIndex; if (nextIndex>=static_cast<int>(vectorSize)) nextIndex = 0;
+
+    return x;
+}
+
+//------------------------------------------------------------------------------
+
+inline unsigned PseudoRandom::nextUnsigned(unsigned to, unsigned from)
+{
+    return from + static_cast<unsigned>(static_cast<double>(to - from) * next()
+                                        / static_cast<double>(MAX));
+}
+
+//------------------------------------------------------------------------------
+
+inline double PseudoRandom::nextDouble(double to, double from)
+{
+    return from + (to-from) * next() / static_cast<double>(MAX);
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_PSEUDORANDOM_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/BufferedStream.h
===================================================================
--- src/hu/varadiistvan/scpl/io/BufferedStream.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/BufferedStream.h	(revision 8)
@@ -0,0 +1,111 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_BUFFEREDSTREAM_H
+#define HU_VARADIISTVAN_SCPL_IO_BUFFEREDSTREAM_H
+//------------------------------------------------------------------------------
+
+#if 0 // The public interface of BufferedStream
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Base class for streams on which a waiter can wait and provides a
+ * reading and/or a writing buffer.
+ */
+class BufferedStream : public Failable
+{
+public:
+    /**
+     * The default buffer capacity.
+     */
+    static const size_t DEFAULT_CAPACITY = 4096;
+
+public:
+    /**
+     * Destroy the buffered stream.
+     */
+    virtual ~BufferedStream();
+
+    /**
+     * Get the reference of the reading buffer. Note, that it can be a
+     * 0 reference, if the stream has no reading buffer.
+     */
+    ReadingBuffer& getReadingBuffer();
+
+    /**
+     * Get the reference of the writing buffer. Note, that it can be a
+     * 0 reference, if the stream has no writing buffer.
+     */
+    WritingBuffer& getWritingBuffer();
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+
+#endif // 0, The public interface of BufferedStream
+
+//------------------------------------------------------------------------------
+
+#include "hu/varadiistvan/scpl/config.h"
+
+//------------------------------------------------------------------------------
+
+#if TARGET_API_POSIX
+
+#include "_posix/BufferedStream.h"
+
+//------------------------------------------------------------------------------
+
+#elif TARGET_API_WIN32 || TARGET_API_WIN64
+
+#include "_win32/BufferedStream.h"
+
+//------------------------------------------------------------------------------
+
+#else
+
+#error "Not implemented for this target!"
+
+#endif
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_BUFFEREDSTREAM_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/LocalAcceptor.h
===================================================================
--- src/hu/varadiistvan/scpl/io/LocalAcceptor.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/LocalAcceptor.h	(revision 8)
@@ -0,0 +1,121 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_LOCALACCEPTOR_H
+#define HU_VARADIISTVAN_SCPL_IO_LOCALACCEPTOR_H
+//------------------------------------------------------------------------------
+
+#if 0 // The public interface of LocalAcceptor
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * An acceptor that provides a LocalSocket for each accepted
+ * connection.
+ */
+class LocalAcceptor : public FailableReference<LocalAcceptor>
+{
+public:
+
+    /**
+     * Start accepting a connection.
+     *
+     * If a connection is already accepted, but not retrieved yet, it
+     * returns true.
+     *
+     * If a new socket becomes immediately available, it returns true.
+     *
+     * If some error occurs, the acceptor is marked as failed.
+     */
+    bool accept();
+
+    /**
+     * Get the local socket accepted last. If no socket was accepted,
+     * return 0. The local socket's waiter will be the given one. If
+     * the server socket has no waiter, this one should be 0. If the
+     * server socket has a waiter, this one should not be 0. In other
+     * words, if the server socket is non-blocking, the accepted one
+     * should also be non-blocking, if the server socket is blocking,
+     * the accepted one should also be blocking.
+     */
+    LocalSocket* getSocket(Waiter* waiter,
+                           size_t readingCapacity = LocalSocket::DEFAULT_CAPACITY,
+                           size_t writingCapacity = LocalSocket::DEFAULT_CAPACITY);
+    /**
+     * Get the local socket accepted last. If no socket was accepted,
+     * return 0. The local socket's waiter will be the same as that of
+     * the associated server socket.
+     */
+    LocalSocket* getSocket(size_t readingCapacity = LocalSocket::DEFAULT_CAPACITY,
+                           size_t writingCapacity = LocalSocket::DEFAULT_CAPACITY);
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+
+#endif // 0, The public interface of LocalAcceptor
+
+//------------------------------------------------------------------------------
+
+#include "hu/varadiistvan/scpl/config.h"
+
+//------------------------------------------------------------------------------
+
+#if TARGET_API_POSIX
+
+#include "_posix/LocalAcceptor.h"
+
+//------------------------------------------------------------------------------
+
+#elif TARGET_API_WIN32 || TARGET_API_WIN64
+
+#include "_win32/LocalAcceptor.h"
+
+//------------------------------------------------------------------------------
+
+#else
+
+#error "Not implemented for this target!"
+
+#endif
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_LOCALACCEPTOR_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/LocalClientSocket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/LocalClientSocket.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/LocalClientSocket.h	(revision 8)
@@ -0,0 +1,112 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_LOCALCLIENTSOCKET_H
+#define HU_VARADIISTVAN_SCPL_IO_LOCALCLIENTSOCKET_H
+//------------------------------------------------------------------------------
+
+#if 0 // The public interface of LocalClientSocket
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+class LocalConnector;
+
+//------------------------------------------------------------------------------
+
+/**
+ * Client socket that connects to a server socket locally. On Linux it
+ * is a Unix socket, on Windows it is a named pipe.
+ *
+ * The server socket's name should be given.
+ */
+class LocalClientSocket : public BufferedStream
+{
+public:
+    /**
+     * Construct the client socket with the given name.
+     *
+     * @param waiter the waiter to use for waiting a possible event
+     * occuring on the socket. If given, the socket will be
+     * non-blocking. Otherwise, it will be blocking, and the connect()
+     * function of the Connector might block as well as the reading
+     * and writing buffers.
+     */
+    LocalClientSocket(const char* name, Waiter* waiter = 0,
+                      size_t readingCapacity = DEFAULT_CAPACITY,
+                      size_t writingCapacity = DEFAULT_CAPACITY);
+
+    /**
+     * Get the connector. Use this object to connect to another socket.
+     */
+    LocalConnector& getConnector();
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+
+#endif // 0, The public interface of LocalClientSocket
+
+//------------------------------------------------------------------------------
+
+#include "hu/varadiistvan/scpl/config.h"
+
+//------------------------------------------------------------------------------
+
+#if TARGET_API_POSIX
+
+#include "_posix/LocalClientSocket.h"
+
+//------------------------------------------------------------------------------
+
+#elif TARGET_API_WIN32 || TARGET_API_WIN64
+
+#include "_win32/LocalClientSocket.h"
+
+//------------------------------------------------------------------------------
+
+#else
+
+#error "Not implemented for this target!"
+
+#endif
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_LOCALCLIENTSOCKET_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/LocalConnector.h
===================================================================
--- src/hu/varadiistvan/scpl/io/LocalConnector.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/LocalConnector.h	(revision 8)
@@ -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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_LOCALCONNECTOR_H
+#define HU_VARADIISTVAN_SCPL_IO_LOCALCONNECTOR_H
+//------------------------------------------------------------------------------
+
+#if 0 // The public interface of LocalConnector
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Class representing the creation of a connection to some remote
+ * entity, like a socket or a pipe. It cannot be created directly,
+ * only acquired from a client socket.
+ */
+class LocalConnector : public FailableReference<LocalConnector>
+{
+public:
+    /**
+     * Connect to an address properly set up.
+     *
+     * If the connection succeeds immediately, it indicates success.
+     *
+     * If the connection does not succeed, because it would block, it
+     * sets up the socket to wait for the connection to succeed, and
+     * returns failure.
+     *
+     * If the connection fails for another reason, the error code is
+     * set, and false is returned.
+     */
+    bool connect();
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+
+#endif // 0, The public interface of LocalConnector
+
+//------------------------------------------------------------------------------
+
+#include "hu/varadiistvan/scpl/config.h"
+
+//------------------------------------------------------------------------------
+
+#if TARGET_API_POSIX
+
+#include "_posix/LocalConnector.h"
+
+//------------------------------------------------------------------------------
+
+#elif TARGET_API_WIN32 || TARGET_API_WIN64
+
+#include "_win32/LocalConnector.h"
+
+//------------------------------------------------------------------------------
+
+#else
+
+#error "Not implemented for this target!"
+
+#endif
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_LOCALCONNECTOR_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/LocalServerSocket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/LocalServerSocket.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/LocalServerSocket.h	(revision 8)
@@ -0,0 +1,108 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_LOCALSERVERSOCKET_H
+#define HU_VARADIISTVAN_SCPL_IO_LOCALSERVERSOCKET_H
+//------------------------------------------------------------------------------
+
+#if 0 // The public interface of LocalServerSocket
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A server socket that provides a local, named access point. On
+ * Linux, it is a Unix socket, on Windows it is a named pipe.
+ *
+ * It is identified by a name that should be unique for the user.
+ */
+class LocalServerSocket
+{
+public:
+    /**
+     * Construct the socket with the given name.
+     *
+     * It will be bound to the name and able to listen for incoming
+     * connections.
+     *
+     * @param waiter the waiter to use for waiting a possible event
+     * occuring on the socket. If given, the socket will be
+     * non-blocking. Otherwise, it will be blocking, and the accept()
+     * function of the Acceptor might block.
+     */
+    LocalServerSocket(const char* name, Waiter* waiter = 0);
+
+    /**
+     * Get the acceptor.
+     */
+    LocalAcceptor& getAcceptor();
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+
+#endif // 0, The public interface of LocalServerSocket
+
+//------------------------------------------------------------------------------
+
+#include "hu/varadiistvan/scpl/config.h"
+
+//------------------------------------------------------------------------------
+
+#if TARGET_API_POSIX
+
+#include "_posix/LocalServerSocket.h"
+
+//------------------------------------------------------------------------------
+
+#elif TARGET_API_WIN32 || TARGET_API_WIN64
+
+#include "_win32/LocalServerSocket.h"
+
+//------------------------------------------------------------------------------
+
+#else
+
+#error "Not implemented for this target!"
+
+#endif
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_LOCALSERVERSOCKET_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/LocalSocket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/LocalSocket.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/LocalSocket.h	(revision 8)
@@ -0,0 +1,88 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_LOCALSOCKET_H
+#define HU_VARADIISTVAN_SCPL_IO_LOCALSOCKET_H
+//------------------------------------------------------------------------------
+
+#if 0 // The public interface of LocalSocket
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A socket that works on a local connection. On Linux, it is a Unix
+ * socket, on Windows it is a named pipe.
+ */
+class LocalSocket : public BufferedStream
+{
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+
+#endif // 0, The public interface of LocalSocket
+
+//------------------------------------------------------------------------------
+
+#include "hu/varadiistvan/scpl/config.h"
+
+//------------------------------------------------------------------------------
+
+#if TARGET_API_POSIX
+
+#include "_posix/LocalSocket.h"
+
+//------------------------------------------------------------------------------
+
+#elif TARGET_API_WIN32 || TARGET_API_WIN64
+
+#include "_win32/LocalSocket.h"
+
+//------------------------------------------------------------------------------
+
+#else
+
+#error "Not implemented for this target!"
+
+#endif
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_LOCALSOCKET_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/Makefile.am
===================================================================
--- src/hu/varadiistvan/scpl/io/Makefile.am	(revision 7)
+++ src/hu/varadiistvan/scpl/io/Makefile.am	(revision 8)
@@ -27,5 +27,11 @@
         Failable.h              \
         Waiter.h                \
+        WaitableEvent.h         \
         ReadingBuffer.h         \
         WritingBuffer.h         \
-        WaitableEvent.h
+        BufferedStream.h        \
+        LocalConnector.h        \
+        LocalClientSocket.h     \
+        LocalSocket.h           \
+        LocalAcceptor.h         \
+        LocalServerSocket.h
Index: src/hu/varadiistvan/scpl/io/_posix/Acceptor.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/Acceptor.cc	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/Acceptor.cc	(revision 8)
@@ -0,0 +1,79 @@
+// 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 "Acceptor.h"
+
+#include "ServerSocket.h"
+
+#include <poll.h>
+#include <sys/socket.h>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::Acceptor;
+
+//------------------------------------------------------------------------------
+
+Acceptor::~Acceptor()
+{
+    delete [] address;
+}
+
+//------------------------------------------------------------------------------
+
+bool Acceptor::accept()
+{
+    if (failed()) return false;
+    if (acceptedFD>=0) return true;
+
+    size_t addrlen = addressLength;
+    int result = socket.accept(reinterpret_cast<struct ::sockaddr*>(address),
+                               (address==0) ? 0 : &addrlen);
+    if (result<0) {
+        if (socket.failed()) {
+            socket.events &= ~POLLIN;
+        } else {
+            socket.events |= POLLIN;
+        }
+        return false;
+    } else {
+        acceptedFD = result;
+        socket.events &= ~POLLIN;
+        return true;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/Acceptor.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/Acceptor.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/Acceptor.h	(revision 8)
@@ -0,0 +1,164 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_POSIX_ACCEPTOR_H
+#define HU_VARADIISTVAN_SCPL_IO_POSIX_ACCEPTOR_H
+//------------------------------------------------------------------------------
+
+#include "../Failable.h"
+
+#include "ServerSocket.h"
+
+#include <cstdlib>
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Class representing the accepting of an incoming connection on a
+ * socket.
+ */
+class Acceptor : public FailableReference<Acceptor>
+{
+protected:
+    /**
+     * The socket we belong to.
+     */
+    ServerSocket& socket;
+
+    /**
+     * The file descriptor accepted the last time.
+     */
+    int acceptedFD;
+
+    /**
+     * The buffer for the remote address, if we are interested.
+     */
+    unsigned char* address;
+
+    /**
+     * The length of the remote address buffer.
+     */
+    size_t addressLength;
+
+protected:
+    /**
+     * Construct the acceptor.
+     *
+     * @param addressLength the length of the buffer for the peer
+     * address. If 0, not buffer will be created.
+     */
+    Acceptor(ServerSocket* socket, size_t addressLength = 0);
+
+public:
+    /**
+     * Destroy the acceptor.
+     */
+    virtual ~Acceptor();
+
+    /**
+     * Start accepting a connection.
+     *
+     * If a connection is already accepted, but not retrieved yet, it
+     * returns true.
+     *
+     * If a new socket becomes immediately available, it returns true.
+     *
+     * If some error occurs, the acceptor is marked as failed.
+     */
+    bool accept();
+
+protected:
+    /**
+     * Called when a connection gets processed and we can become ready
+     * for the next one.
+     */
+    void connectionProcessed();
+
+private:
+    /**
+     * Get the failable object.
+     */
+    const Failable& getFailable() const;
+
+    /**
+     * Get the failable object.
+     */
+    Failable& getFailable();
+
+    friend class FailableReference<Acceptor>;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Acceptor::Acceptor(ServerSocket* socket, size_t addressLength) :
+    socket(*socket),
+    acceptedFD(-1),
+    address( (addressLength==0) ? 0 : new unsigned char[addressLength]),
+    addressLength(addressLength)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline void Acceptor::connectionProcessed()
+{
+    acceptedFD = -1;
+}
+
+//------------------------------------------------------------------------------
+
+inline const Failable& Acceptor::getFailable() const
+{
+    return socket;
+}
+
+//------------------------------------------------------------------------------
+
+inline Failable& Acceptor::getFailable()
+{
+    return socket;
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_POSIX_ACCEPTOR_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/ClientSocket.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/ClientSocket.cc	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/ClientSocket.cc	(revision 8)
@@ -0,0 +1,72 @@
+// 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 "ClientSocket.h"
+
+#include "Connector.h"
+
+#include <poll.h>
+
+#include <sys/socket.h>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::ClientSocket;
+
+//------------------------------------------------------------------------------
+
+void ClientSocket::handleEvents(short events)
+{
+    if (connector.connecting && (events&POLLOUT)==POLLOUT) {
+        connector.handleWritable();
+        events &= ~POLLOUT;
+    }
+
+    BufferedStream::handleEvents(events);
+}
+
+//------------------------------------------------------------------------------
+
+bool ClientSocket::connect(const struct sockaddr* addr, size_t addrlen)
+{
+    int result = ::connect(fd, addr, addrlen);
+    if (result<0 && errno!=EINPROGRESS) {
+        setErrorCodeFromErrno();
+    }
+    return result>=0;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/ClientSocket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/ClientSocket.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/ClientSocket.h	(revision 8)
@@ -0,0 +1,111 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_POSIX_CLIENTSOCKET_H
+#define HU_VARADIISTVAN_SCPL_IO_POSIX_CLIENTSOCKET_H
+//------------------------------------------------------------------------------
+
+#include "Socket.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+class Connector;
+
+//------------------------------------------------------------------------------
+
+/**
+ * A socket that can be connected to another one.
+ */
+class ClientSocket : public Socket
+{
+private:
+    /**
+     * The connector.
+     */
+    Connector& connector;
+
+protected:
+    /**
+     * Construct the socket with the given parameters.
+     */
+    ClientSocket(int domain, int type, Connector& connector,
+                 Waiter* waiter = 0, int protocol = 0,
+                 size_t readingCapacity = DEFAULT_CAPACITY,
+                 size_t writingCapacity = DEFAULT_CAPACITY);
+
+protected:
+    /**
+     * Handle any events on the file descriptor. If a connection is in
+     * progress, and the incoming events have the EPOLLOUT flag set,
+     * the connector is called to handle the event. Then the parent
+     * class' handleEvents function is called.
+     */
+    virtual void handleEvents(short events);
+
+    /**
+     * Connect the socket to the given address.
+     *
+     * @return whether the connection succeeded or not. If it does not
+     * succeeded, it may be either because of the socket being
+     * non-blocking and some time is needed, or because of a failure,
+     * in which case the error code will be set properly.
+     */
+    bool connect(const struct sockaddr* addr, size_t addrlen);
+
+    friend class Connector;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline ClientSocket::ClientSocket(int domain, int type, Connector& connector,
+                                  Waiter* waiter, int protocol,
+                                  size_t readingCapacity,
+                                  size_t writingCapacity) :
+    Socket(domain, type, waiter, protocol, readingCapacity, writingCapacity),
+    connector(connector)
+{
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_POSIX_CLIENTSOCKET_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/Connector.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/Connector.cc	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/Connector.cc	(revision 8)
@@ -0,0 +1,92 @@
+// 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 "Connector.h"
+
+#include "ClientSocket.h"
+
+#include <poll.h>
+#include <sys/socket.h>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::Connector;
+
+//------------------------------------------------------------------------------
+
+bool Connector::connect()
+{
+    if (connected) return true;
+    if (connecting || failed()) return false;
+
+    size_t addrlen = 0;
+    const struct sockaddr* addr = getAddress(addrlen);
+
+    if (socket.connect(addr, addrlen)) {
+        connected = true;
+        return true;
+    } else if (socket.failed()) {
+        return false;
+    } else {
+        connecting = true;
+        socket.events |= POLLOUT;
+        return false;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+void Connector::handleWritable()
+{
+    if (!connecting) return;
+
+    connecting = false;
+    socket.events &= ~POLLOUT;
+
+    int error = 0;
+    socklen_t len = sizeof(error);
+    if (getsockopt(socket.fd, SOL_SOCKET, SO_ERROR, &error, &len)<0) {
+        socket.setErrorCodeFromErrno();
+    } else {
+        if (error==0) {
+            connected = true;
+        } else {
+            socket.setErrorCode(error);
+        }
+    }
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/Connector.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/Connector.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/Connector.h	(revision 8)
@@ -0,0 +1,162 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_POSIX_CONNECTOR_H
+#define HU_VARADIISTVAN_SCPL_IO_POSIX_CONNECTOR_H
+//------------------------------------------------------------------------------
+
+#include "../Failable.h"
+
+#include "ClientSocket.h"
+
+#include <cstdlib>
+
+//------------------------------------------------------------------------------
+
+struct sockaddr;
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Class representing the creation of a connection to some remote
+ * entity, like a socket or a pipe.
+ */
+class Connector : public FailableReference<Connector>
+{
+private:
+    /**
+     * The socket on behalf of which the connection is being
+     * performed.
+     */
+    ClientSocket& socket;
+
+    /**
+     * Indicate that we are in the process of connecting.
+     */
+    bool connecting;
+
+    /**
+     * Indicate that we are connected.
+     */
+    bool connected;
+
+protected:
+    /**
+     * Construct the connector.
+     */
+    Connector(ClientSocket* socket);
+
+public:
+    /**
+     * Connect to an address properly set up.
+     *
+     * If the connection succeeds immediately, it indicates success.
+     *
+     * If the connection does not succeed, because it would block, it
+     * sets up the socket to wait for the connection to succeed, and
+     * returns failure.
+     *
+     * If the connection fails for another reason, the error code is
+     * set, and false is returned.
+     */
+    bool connect();
+
+protected:
+    /**
+     * Get the parameters for connecting.
+     */
+    virtual const struct sockaddr* getAddress(size_t& addrlen) = 0;
+
+    /**
+     * Handle the event that the socket is writable.
+     *
+     * If connection is in progress, this function returns
+     * immediately.
+     *
+     * Otherwise it reads the error code using getsockopt(), and if it
+     * indicates success, the connector is set to connected, otherwise
+     * it is set to failed.
+     */
+    void handleWritable();
+
+private:
+    /**
+     * Get the failable object.
+     */
+    const Failable& getFailable() const;
+
+    /**
+     * Get the failable object.
+     */
+    Failable& getFailable();
+
+    friend class FailableReference<Connector>;
+    friend class ClientSocket;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Connector::Connector(ClientSocket* socket) :
+    socket(*socket),
+    connecting(false),
+    connected(false)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline const Failable& Connector::getFailable() const
+{
+    return socket;
+}
+
+//------------------------------------------------------------------------------
+
+inline Failable& Connector::getFailable()
+{
+    return socket;
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_POSIX_CONNECTOR_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/LocalAcceptor.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/LocalAcceptor.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/LocalAcceptor.h	(revision 8)
@@ -0,0 +1,121 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALACCEPTOR_H
+#define HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALACCEPTOR_H
+//------------------------------------------------------------------------------
+
+#include "Acceptor.h"
+
+#include "LocalSocket.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * An acceptor that provides a LocalSocket for each accepted
+ * connection.
+ */
+class LocalAcceptor : public Acceptor
+{
+private:
+    /**
+     * Construct the acceptor.
+     *
+     * @param addressLength the length of the buffer for the peer
+     * address. If 0, not buffer will be created.
+     */
+    LocalAcceptor(ServerSocket* socket);
+
+public:
+    /**
+     * Get the local socket accepted last. If no socket was accepted,
+     * return 0. The local socket's waiter will be the given one
+     * (which can be 0).
+     */
+    LocalSocket* getSocket(Waiter* waiter,
+                           size_t readingCapacity = LocalSocket::DEFAULT_CAPACITY,
+                           size_t writingCapacity = LocalSocket::DEFAULT_CAPACITY);
+    /**
+     * Get the local socket accepted last. If no socket was accepted,
+     * return 0. The local socket's waiter will be the same as that of
+     * the associated server socket.
+     */
+    LocalSocket* getSocket(size_t readingCapacity = LocalSocket::DEFAULT_CAPACITY,
+                           size_t writingCapacity = LocalSocket::DEFAULT_CAPACITY);
+
+
+    friend class LocalServerSocket;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline LocalAcceptor::LocalAcceptor(ServerSocket* socket) :
+    Acceptor(socket)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline LocalSocket* LocalAcceptor::getSocket(Waiter* waiter,
+                                             size_t readingCapacity,
+                                             size_t writingCapacity)
+{
+    if (acceptedFD<0) return 0;
+
+    LocalSocket* socket = new LocalSocket(acceptedFD, waiter,
+                                          readingCapacity, writingCapacity);
+    connectionProcessed();
+    return socket;
+}
+
+//------------------------------------------------------------------------------
+
+inline LocalSocket* LocalAcceptor::getSocket(size_t readingCapacity,
+                                             size_t writingCapacity)
+{
+    return getSocket(socket.getWaiter(), readingCapacity, writingCapacity);
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALACCEPTOR_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/LocalClientSocket.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/LocalClientSocket.cc	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/LocalClientSocket.cc	(revision 8)
@@ -0,0 +1,58 @@
+// 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 "LocalClientSocket.h"
+
+#include "LocalConnector.h"
+
+#include <sys/socket.h>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::LocalClientSocket;
+
+//------------------------------------------------------------------------------
+
+LocalClientSocket::LocalClientSocket(const char* name, Waiter* waiter,
+                                     size_t readingCapacity,
+                                     size_t writingCapacity) :
+    ClientSocket(AF_UNIX, SOCK_STREAM, connector, waiter, 0,
+                 readingCapacity, writingCapacity),
+    connector(this, name)
+{
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/LocalClientSocket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/LocalClientSocket.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/LocalClientSocket.h	(revision 8)
@@ -0,0 +1,100 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALCLIENTSOCKET_H
+#define HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALCLIENTSOCKET_H
+//------------------------------------------------------------------------------
+
+#include "ClientSocket.h"
+
+#include "LocalConnector.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Client socket that connects to a server socket locally (i.e. a Unit
+ * socket).
+ *
+ * The server socket's name should be given. The name will be used as
+ * described for LocalServerSocket.
+ */
+class LocalClientSocket : public ClientSocket
+{
+private:
+    /**
+     * The address to use for connecting.
+     */
+    LocalConnector connector;
+
+public:
+    /**
+     * Construct the client socket with the given name.
+     *
+     * @param waiter the waiter to use for waiting a possible event
+     * occuring on the socket. If given, the socket will be
+     * non-blocking. Otherwise, it will be blocking, and the connect()
+     * function of the Connector might block as well as the reading
+     * and writing buffers.
+     */
+    LocalClientSocket(const char* name, Waiter* waiter = 0,
+                      size_t readingCapacity = DEFAULT_CAPACITY,
+                      size_t writingCapacity = DEFAULT_CAPACITY);
+
+    /**
+     * Get the connector for this client.
+     */
+    LocalConnector& getConnector();
+
+    friend class LocalConnector;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline LocalConnector& LocalClientSocket::getConnector()
+{
+    return connector;
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALCLIENTSOCKET_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/LocalConnector.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/LocalConnector.cc	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/LocalConnector.cc	(revision 8)
@@ -0,0 +1,51 @@
+// 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 "LocalConnector.h"
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::LocalConnector;
+
+//------------------------------------------------------------------------------
+
+const struct sockaddr* LocalConnector::getAddress(size_t& addrlen)
+{
+    addrlen = sizeof(address);
+    return reinterpret_cast<const struct sockaddr*>(&address);
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/LocalConnector.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/LocalConnector.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/LocalConnector.h	(revision 8)
@@ -0,0 +1,89 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALCONNECTOR_H
+#define HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALCONNECTOR_H
+//------------------------------------------------------------------------------
+
+#include "Connector.h"
+
+#include "LocalServerSocket.h"
+
+#include <sys/socket.h>
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * The connector class used by the local client socket.
+ */
+class LocalConnector : public Connector
+{
+private:
+    /**
+     * The reference to the corresponding socket's address.
+     */
+    struct sockaddr_un address;
+
+public:
+    /**
+     * Create the connector for the given local client socket.
+     */
+    LocalConnector(ClientSocket* socket, const char* name);
+
+protected:
+    /**
+     * Get the address.
+     */
+    virtual const struct sockaddr* getAddress(size_t& addrlen);
+};
+
+//------------------------------------------------------------------------------
+
+inline LocalConnector::LocalConnector(ClientSocket* socket, const char* name) :
+    Connector(socket)
+{
+    address.sun_family = AF_UNIX;
+    LocalServerSocket::setupPath(address, name);
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALCONNECTOR_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/LocalServerSocket.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/LocalServerSocket.cc	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/LocalServerSocket.cc	(revision 8)
@@ -0,0 +1,109 @@
+// 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 "LocalServerSocket.h"
+
+#include <cstdio>
+
+#include <pwd.h>
+#include <unistd.h>
+#include <poll.h>
+
+#include <sys/socket.h>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::LocalServerSocket;
+
+//------------------------------------------------------------------------------
+
+void LocalServerSocket::setupPath(struct sockaddr_un& addr, const char* name)
+{
+#ifndef P_tmpdir
+#define P_tmpdir "/tmp"
+#endif
+    struct passwd* passwd = getpwuid(geteuid());
+    const char* userName = (passwd==0) ? "unknown" : passwd->pw_name;
+    snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s-%s",
+             P_tmpdir, name, userName);
+}
+
+//------------------------------------------------------------------------------
+
+LocalServerSocket::LocalServerSocket(const char* name, Waiter* waiter) :
+    ServerSocket(AF_UNIX, SOCK_STREAM, waiter),
+    acceptor(this)
+{
+    sun.sun_family = AF_UNIX;
+    setupPath(sun, name);
+
+    unlink(sun.sun_path);
+
+    if (bind(reinterpret_cast<struct sockaddr*>(&sun), sizeof(sun), false)<0) {
+        setErrorCode(errno);
+        return;
+    }
+
+    if (listen()<0) {
+        setErrorCode(errno);
+        return;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+LocalServerSocket::~LocalServerSocket()
+{
+    unlink(sun.sun_path);
+}
+
+//------------------------------------------------------------------------------
+
+bool LocalServerSocket::isReady()
+{
+    return false;
+}
+
+//------------------------------------------------------------------------------
+
+void LocalServerSocket::handleEvents(short events)
+{
+    if ((events&POLLIN)==POLLIN) {
+        acceptor.accept();
+    }
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/LocalServerSocket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/LocalServerSocket.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/LocalServerSocket.h	(revision 8)
@@ -0,0 +1,130 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALSERVERSOCKET_H
+#define HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALSERVERSOCKET_H
+//------------------------------------------------------------------------------
+
+#include "ServerSocket.h"
+
+#include "LocalAcceptor.h"
+
+#include <sys/un.h>
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A server socket that works locally, i.e. a Unix socket.
+ *
+ * It is identified by a name that should be unique for the user. The
+ * actual socket will be created with the name /tmp/<name>-<username>.
+ */
+class LocalServerSocket : public ServerSocket
+{
+public:
+    /**
+     * Fill in the path of the socket with the given name.
+     */
+    static void setupPath(struct sockaddr_un& addr, const char* name);
+
+private:
+    /**
+     * Our address (to be used when deleting the file in the
+     * destructor.
+     */
+    struct sockaddr_un sun;
+
+    /**
+     * The acceptor to use for accepting connections.
+     */
+    LocalAcceptor acceptor;
+
+public:
+    /**
+     * Construct the socket with the given name.
+     *
+     * It will be bound to the name and able to listen for incoming
+     * connections.
+     *
+     * @param waiter the waiter to use for waiting a possible event
+     * occuring on the socket. If given, the socket will be
+     * non-blocking. Otherwise, it will be blocking, and the accept()
+     * function of the Acceptor might block.
+     */
+    LocalServerSocket(const char* name, Waiter* waiter = 0);
+
+    /**
+     * Destroy the socket by deleting the file.
+     */
+    virtual ~LocalServerSocket();
+
+    /**
+     * Get the acceptor.
+     */
+    LocalAcceptor& getAcceptor();
+
+protected:
+    /**
+     * Indicate if the waitable is ready, i.e. there is no need to
+     * wait for it.
+     */
+    virtual bool isReady();
+
+    /**
+     * Handle the given events.
+     */
+    virtual void handleEvents(short events);
+
+    friend class LocalAcceptor;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline LocalAcceptor& LocalServerSocket::getAcceptor()
+{
+    return acceptor;
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALSERVERSOCKET_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/LocalSocket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/LocalSocket.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/LocalSocket.h	(revision 8)
@@ -0,0 +1,79 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALSOCKET_H
+#define HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALSOCKET_H
+//------------------------------------------------------------------------------
+
+#include "Socket.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A socket that works on a local (Unix) connection.
+ */
+class LocalSocket : public Socket
+{
+private:
+    /**
+     * Construct the socket with the given parameters.
+     */
+    LocalSocket(int fd, Waiter* waiter = 0,
+                size_t readingCapacity = DEFAULT_CAPACITY,
+                size_t writingCapacity = DEFAULT_CAPACITY);
+
+    friend class LocalAcceptor;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline LocalSocket::LocalSocket(int fd, Waiter* waiter,
+                                size_t readingCapacity,
+                                size_t writingCapacity) :
+    Socket(fd, waiter, readingCapacity, writingCapacity)
+{
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_POSIX_LOCALSOCKET_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/Makefile.am
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/Makefile.am	(revision 7)
+++ src/hu/varadiistvan/scpl/io/_posix/Makefile.am	(revision 8)
@@ -8,8 +8,16 @@
         Waitable.cc             \
         Waiter.cc               \
+        WaitableEvent.cc        \
         BufferedStream.cc       \
         ReadingBuffer.cc        \
         WritingBuffer.cc        \
-        WaitableEvent.cc
+        Socket.cc               \
+        Connector.cc            \
+        ClientSocket.cc         \
+        LocalConnector.cc       \
+        LocalClientSocket.cc    \
+        Acceptor.cc             \
+        ServerSocket.cc         \
+        LocalServerSocket.cc
 
 include_vscpl_io_posixdir=$(includedir)/hu/varadiistvan/scpl/io/_posix
@@ -17,7 +25,17 @@
         Waitable.h              \
         Waiter.h                \
+        WaitableEvent.h         \
         BufferedStream.h        \
         StreamBuffer.h          \
         ReadingBuffer.h         \
         WritingBuffer.h         \
-        WaitableEvent.h
+        Socket.h                \
+        Connector.h             \
+        ClientSocket.h          \
+        LocalConnector.h        \
+        LocalClientSocket.h     \
+        Acceptor.h              \
+        ServerSocket.h          \
+        LocalSocket.h           \
+        LocalAcceptor.h         \
+        LocalServerSocket.h
Index: src/hu/varadiistvan/scpl/io/_posix/ServerSocket.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/ServerSocket.cc	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/ServerSocket.cc	(revision 8)
@@ -0,0 +1,112 @@
+// 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 "ServerSocket.h"
+
+#include "Socket.h"
+
+#include <unistd.h>
+#include <sys/socket.h>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::ServerSocket;
+using hu::varadiistvan::scpl::io::Acceptor;
+
+//------------------------------------------------------------------------------
+
+ServerSocket::ServerSocket(int domain, int type, Waiter* waiter, int protocol) :
+    Waitable(waiter, Socket::socket(domain, type, protocol))
+{
+    if (fd<0) setErrorCodeFromErrno();
+    else if (waiter!=0) setNonBlocking(fd);
+}
+
+//------------------------------------------------------------------------------
+
+ServerSocket::~ServerSocket()
+{
+    if (fd>=0) ::close(fd);
+}
+
+//------------------------------------------------------------------------------
+
+bool ServerSocket::bind(const struct sockaddr* addr, size_t addrlen,
+                        bool reuseaddr)
+{
+    if (reuseaddr) {
+        int reuse = 1;
+        if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse))<0) {
+            setErrorCodeFromErrno();
+            return false;
+        }
+    }
+
+    if (::bind(fd, addr, addrlen)<0) {
+        setErrorCodeFromErrno();
+        return false;
+    }
+
+    return true;
+}
+
+//------------------------------------------------------------------------------
+
+bool ServerSocket::listen(int backlog)
+{
+    if (::listen(fd, backlog)<0) {
+        setErrorCodeFromErrno();
+        return false;
+    } else {
+        return true;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+int ServerSocket::accept(struct sockaddr* addr, size_t* addrlen)
+{
+    socklen_t alen = (addrlen==0) ? 0 : *addrlen;
+    int result = ::accept(fd, addr, (addrlen==0) ? 0 : &alen);
+    if (result<0 && errno!=EAGAIN && errno!=EWOULDBLOCK) {
+        setErrorCodeFromErrno();
+    } else {
+        if (addrlen!=0) *addrlen = alen;
+    }
+    return result;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/ServerSocket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/ServerSocket.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/ServerSocket.h	(revision 8)
@@ -0,0 +1,114 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_POSIX_SERVERSOCKET_H
+#define HU_VARADIISTVAN_SCPL_IO_POSIX_SERVERSOCKET_H
+//------------------------------------------------------------------------------
+
+#include "Waitable.h"
+
+#include <cstdlib>
+
+//------------------------------------------------------------------------------
+
+struct sockaddr;
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+class Acceptor;
+
+//------------------------------------------------------------------------------
+
+/**
+ * A socket in a server role. It can only bind to a new address,
+ * listen and accept connections. It cannot connect to other sockets
+ * and cannot be read or written.
+ */
+class ServerSocket : public Waitable
+{
+protected:
+    /**
+     * Construct the server socket.
+     */
+    ServerSocket(int domain, int type, Waiter* waiter = 0, int protocol = 0);
+
+public:
+    /**
+     * Destroy the server socket.
+     */
+    virtual ~ServerSocket();
+
+protected:
+    /**
+     * Bind the socket to the given address.
+     *
+     * @param reuseaddr if set to true, the SO_REUSEADDR socket option
+     * will be set.
+     *
+     * @return if the binding has succeeded. If it is false, the error
+     * code will be set accordingly.
+     */
+    bool bind(const struct sockaddr* addr, size_t addrlen,
+              bool reuseaddr = true);
+
+    /**
+     * Start listening on the socket.
+     *
+     * @return if the call has succeeded. If it is false, the error
+     * code will be set accordingly.
+     */
+    bool listen(int backlog = 5);
+
+    /**
+     * Accept a socket.
+     *
+     * @return the accepted socket. If may be -1, if the socket is
+     * non-blocking, and no connection is available yet, or if another
+     * error occured, in which case the error code will be set properly.
+     */
+    int accept(struct sockaddr* addr, size_t* addrlen);
+
+    friend class Acceptor;
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_POSIX_SERVERSOCKET_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/Socket.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/Socket.cc	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/Socket.cc	(revision 8)
@@ -0,0 +1,60 @@
+// 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 "Socket.h"
+
+#include <unistd.h>
+#include <sys/socket.h>
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::Socket;
+
+//------------------------------------------------------------------------------
+
+int Socket::socket(int domain, int type, int protocol)
+{
+    return ::socket(domain, type, protocol);
+}
+
+//------------------------------------------------------------------------------
+
+Socket::~Socket()
+{
+    if (fd>=0) ::close(fd);
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_posix/Socket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_posix/Socket.h	(revision 8)
+++ src/hu/varadiistvan/scpl/io/_posix/Socket.h	(revision 8)
@@ -0,0 +1,113 @@
+// 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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_POSIX_SOCKET_H
+#define HU_VARADIISTVAN_SCPL_IO_POSIX_SOCKET_H
+//------------------------------------------------------------------------------
+
+#include "BufferedStream.h"
+
+//------------------------------------------------------------------------------
+
+struct sockaddr;
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A buffered, waitable socket implementation.
+ */
+class Socket : public BufferedStream
+{
+private:
+    /**
+     * Construct a socket with the given parameters.
+     */
+    static int socket(int domain, int type, int protocol);
+
+protected:
+    /**
+     * Construct the socket with the given parameters.
+     */
+    Socket(int domain, int type, Waiter* waiter = 0, int protocol = 0,
+           size_t readingCapacity = DEFAULT_CAPACITY,
+           size_t writingCapacity = DEFAULT_CAPACITY);
+
+    /**
+     * Construct the socket with the given file descriptor.
+     */
+    Socket(int fd, Waiter* waiter = 0,
+           size_t readingCapacity = DEFAULT_CAPACITY,
+           size_t writingCapacity = DEFAULT_CAPACITY);
+
+public:
+    /**
+     * Destroy the socket by closing the file descriptor.
+     */
+    virtual ~Socket();
+
+    friend class ServerSocket;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Socket::Socket(int domain, int type, Waiter* waiter, int protocol,
+                      size_t readingCapacity, size_t writingCapacity) :
+    BufferedStream(waiter, socket(domain, type, protocol),
+                     readingCapacity, writingCapacity)
+{
+    if (fd<0) setErrorCodeFromErrno();
+    else if (waiter!=0) setNonBlocking(fd);
+}
+
+//------------------------------------------------------------------------------
+
+inline Socket::Socket(int fd, Waiter* waiter,
+                      size_t readingCapacity, size_t writingCapacity) :
+    BufferedStream(waiter, fd, readingCapacity, writingCapacity)
+{
+    if (waiter!=0) setNonBlocking(fd);
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_POSIX_SOCKET_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
