Index: src/hu/varadiistvan/scpl/io/_win32/BufferedStream.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/BufferedStream.cc	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/BufferedStream.cc	(revision 9)
@@ -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 "BufferedStream.h"
+
+#include "ReadingBuffer.h"
+#include "WritingBuffer.h"
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::BufferedStream;
+
+//------------------------------------------------------------------------------
+
+BufferedStream::BufferedStream(Waiter* waiter, HANDLE handle,
+                               size_t readingCapacity, size_t writingCapacity) :
+    Overlappable(waiter, handle),
+    readingBuffer( (readingCapacity==0) ? 0 :
+                   new ReadingBuffer(readingCapacity, this)),
+    writingBuffer( (writingCapacity==0) ? 0 :
+                   new WritingBuffer(writingCapacity, this))
+{
+}
+
+//------------------------------------------------------------------------------
+
+BufferedStream::~BufferedStream()
+{
+    delete writingBuffer;
+    delete readingBuffer;
+}
+
+//------------------------------------------------------------------------------
+
+ssize_t BufferedStream::read(void* dest, size_t length, Overlapped* overlapped)
+{
+    DWORD numRead = 0;
+    if (overlapped!=0) overlapped->reset();
+    bool result = ReadFile(handle, dest, length,
+                           (overlapped==0) ? &numRead : 0,
+                           (overlapped==0) ? 0 : overlapped->get());
+    DWORD error = GetLastError();
+    if (!result &&
+        (overlapped==0 ||
+         (error!=ERROR_IO_PENDING && error!=ERROR_IO_INCOMPLETE)))
+    {
+        setErrorCode(error);
+        return -1;
+    } else if (overlapped==0 || overlapped->getResult(numRead, handle)) {
+        return numRead;
+    } else {
+        return -1;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+bool BufferedStream::write(const void* src, size_t length,
+                           Overlapped* overlapped)
+{
+    if (overlapped!=0) overlapped->reset();
+    bool result = WriteFile(handle, src, length, 0,
+                            (overlapped==0) ? 0 : overlapped->get());
+    DWORD error = GetLastError();
+    if (!result &&
+        (overlapped==0 ||
+         (error!=ERROR_IO_PENDING && error!=ERROR_IO_INCOMPLETE)))
+    {
+        setErrorCode(error);
+        return false;
+    } else if (overlapped==0) {
+        return result;
+    } else {
+        DWORD numWritten = 0;
+        return overlapped->getResult(numWritten, handle);
+    }
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/BufferedStream.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/BufferedStream.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/BufferedStream.h	(revision 9)
@@ -0,0 +1,152 @@
+// 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_WIN32_BUFFEREDSTREAM_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_BUFFEREDSTREAM_H
+//------------------------------------------------------------------------------
+
+#include "Overlappable.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+class ReadingBuffer;
+class WritingBuffer;
+class Overlapped;
+
+//------------------------------------------------------------------------------
+
+/**
+ * A buffered stream.
+ *
+ * It wraps a HANDLE which can be read and/or written with ReadFile or
+ * WriteFile, respectively.
+ */
+class BufferedStream : public Overlappable
+{
+public:
+    /**
+     * The default capacity.
+     */
+    static const size_t DEFAULT_CAPACITY = 4096;
+
+private:
+    /**
+     * The reading buffer. It may be 0, if no reading buffer is
+     * associated with this waitable.
+     */
+    ReadingBuffer* readingBuffer;
+
+    /**
+     * The writing buffer. It may be 0, if no writing buffer is
+     * associated with this waitable.
+     */
+    WritingBuffer* writingBuffer;
+
+protected:
+    /**
+     * Construct the buffered stream.
+     */
+    BufferedStream(Waiter* waiter = 0, HANDLE handle = 0,
+                   size_t readingCapacity = DEFAULT_CAPACITY,
+                   size_t writingCapacity = DEFAULT_CAPACITY);
+
+public:
+    /**
+     * Destroy the 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();
+
+protected:
+    /**
+     * Read using the handle at most the given number of bytes into
+     * the given buffer.
+     *
+     * @return the number of bytes read. If 0, it indicates the end of
+     * the file or connection. If negative, it means either a failure,
+     * or the fact that the operation cannot be completed at this time.
+     */
+    ssize_t read(void* dest, size_t length, Overlapped* overlapped);
+
+    /**
+     * Write using the handle the given number of bytes from the given
+     * buffer.
+     *
+     * @return whether the writing succeeded. If false, it is either a
+     * failure, or an inidication of the fact that the operation could
+     * not be completed.
+     */
+    bool write(const void* src, size_t length, Overlapped* overlapped);
+
+    friend class ReadingBuffer;
+    friend class WritingBuffer;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline ReadingBuffer& BufferedStream::getReadingBuffer()
+{
+    return *readingBuffer;
+}
+
+//------------------------------------------------------------------------------
+
+inline WritingBuffer& BufferedStream::getWritingBuffer()
+{
+    return *writingBuffer;
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_BUFFEREDSTREAM_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/Completer.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/Completer.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/Completer.h	(revision 9)
@@ -0,0 +1,219 @@
+// 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_WIN32_COMPLETER_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_COMPLETER_H
+//------------------------------------------------------------------------------
+
+#include "../Failable.h"
+
+#include "Overlapped.h"
+#include "Overlappable.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Base class for objects that handle the completion of some
+ * operation. They are associated with an Overlappable, and if that
+ * overlappable is non-blocking (i.e. has a waiter), an Overlapped
+ * object is created and stored in this object.
+ */
+class Completer : public FailableReference<Completer>
+{
+protected:
+    /**
+     * The overlappable object this completer belongs to.
+     */
+    Overlappable& overlappable;
+
+    /**
+     * The overlapped object.
+     */
+    Overlapped* overlapped;
+
+protected:
+    /**
+     * Construct the completer for the given Overlappable.
+     */
+    Completer(Overlappable* overlappable);
+
+    /**
+     * Destroy the completer.
+     */
+    virtual ~Completer();
+
+    /**
+     * Add the overlapped object (if any) to the given waiter.
+     */
+    void addTo(Waiter* waiter);
+
+    /**
+     * Remove the overlapped object (if any) from the waiter it is
+     * associated with.
+     */
+    void removeFromWaiter();
+
+    /**
+     * Determine if there is an overlapped object and it is being
+     * waited for.
+     */
+    bool isWaited() const;
+
+    /**
+     * Get the result of the overlapped operation, if any.
+     *
+     * @see Overlapped::getResult
+     */
+    bool getResult(DWORD& size);
+
+    /**
+     * Check whether we are waiting for an overlapped result and if
+     * so, return that.
+     *
+     * @param result will contain the result to return if we are
+     * waiting for an overlapped result.
+     *
+     * @return whether we are waiting for an overlapped result
+     */
+    bool checkWaitedResult(bool& result);
+
+    /**
+     * Handle the given result coming from an overlapped object.
+     */
+    virtual void handleWaitedResult(DWORD size) = 0;
+
+private:
+    /**
+     * Get the failable object.
+     */
+    const Failable& getFailable() const;
+
+    /**
+     * Get the failable object.
+     */
+    Failable& getFailable();
+
+    friend class FailableReference<Completer>;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Completer::Completer(Overlappable* overlappable) :
+    overlappable(*overlappable),
+    overlapped((overlappable->waiter==0) ? 0 : new Overlapped(*overlappable))
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline Completer::~Completer()
+{
+    delete overlapped;
+}
+
+//------------------------------------------------------------------------------
+
+inline void Completer::addTo(Waiter* waiter)
+{
+    if (overlapped!=0 && waiter!=0) overlapped->addTo(*waiter);
+}
+
+//------------------------------------------------------------------------------
+
+inline void Completer::removeFromWaiter()
+{
+    if (overlapped!=0) overlapped->removeFromWaiter();
+}
+
+//------------------------------------------------------------------------------
+
+inline bool Completer::isWaited() const
+{
+    return overlapped!=0 && overlapped->isWaited();
+}
+
+//------------------------------------------------------------------------------
+
+inline bool Completer::getResult(DWORD& size)
+{
+    return overlapped!=0 && overlapped->getResult(size, overlappable.handle);
+}
+
+//------------------------------------------------------------------------------
+
+inline bool Completer::checkWaitedResult(bool& result)
+{
+    if (!isWaited()) {
+        return false;
+    }
+
+    DWORD size = 0;
+    result = getResult(size);
+
+    if (result) {
+        removeFromWaiter();
+        handleWaitedResult(size);
+    } else if (overlappable.failed()) {
+        removeFromWaiter();
+    }
+
+    return true;
+}
+
+//------------------------------------------------------------------------------
+
+inline const Failable& Completer::getFailable() const
+{
+    return overlappable;
+}
+
+//------------------------------------------------------------------------------
+
+inline Failable& Completer::getFailable()
+{
+    return overlappable;
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_COMPLETER_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/LocalAcceptor.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/LocalAcceptor.cc	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/LocalAcceptor.cc	(revision 9)
@@ -0,0 +1,86 @@
+// 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 "LocalAcceptor.h"
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::LocalAcceptor;
+
+//------------------------------------------------------------------------------
+
+LocalAcceptor::LocalAcceptor(LocalServerSocketBase* socket, const char* name) :
+    Completer(socket),
+    accepted(false)
+{
+    LocalSocket::setupPath(path, name);
+}
+
+//------------------------------------------------------------------------------
+
+bool LocalAcceptor::accept()
+{
+    if (failed()) return false;
+    if (accepted) return true;
+
+    bool result = false;
+    if (checkWaitedResult(result)) {
+        return result;
+    }
+
+    LocalServerSocketBase& socket = getServerSocket();
+    if (!socket.createNamedPipe(path)) {
+        return false;
+    }
+
+    result = socket.connectNamedPipe(overlapped);
+    if (result) {
+        accepted = true;
+    } else if (!socket.failed()) {
+        addTo(socket.waiter);
+    }
+
+    return result;
+}
+
+//------------------------------------------------------------------------------
+
+void LocalAcceptor::handleWaitedResult(DWORD /*size*/)
+{
+    accepted = true;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/LocalAcceptor.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/LocalAcceptor.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/LocalAcceptor.h	(revision 9)
@@ -0,0 +1,160 @@
+// 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_WIN32_LOCALACCEPTOR_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_LOCALACCEPTOR_H
+//------------------------------------------------------------------------------
+
+#include "Completer.h"
+
+#include "LocalServerSocketBase.h"
+#include "LocalSocket.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Instances of this class are used to accept connection requests to a
+ * local server socket, i.e. named pipe.
+ */
+class LocalAcceptor : public Completer
+{
+private:
+    /**
+     * The path of the pipe to accept.
+     */
+    char path[256];
+
+    /**
+     * Indicate if the connection has been accepted.
+     */
+    bool accepted;
+
+protected:
+    /**
+     * Construct the acceptor.
+     */
+    LocalAcceptor(LocalServerSocketBase* socket, const char* name);
+
+    /**
+     * Get the socket.
+     *
+     * It returns the overlappable from the Completer part, knowing
+     * that it must be a LocalServerSocketBase.
+     */
+    LocalServerSocketBase& getServerSocket() const;
+
+public:
+    /**
+     * Try to accept a connection.
+     *
+     * If one is already accepted, but not retrieved yet, return true.
+     *
+     * If a new connection becomes immediately available, return true.
+     *
+     * If a new connection is not yet available, returns false.
+     *
+     * If some error occurs, the acceptor is marked failed and false
+     * is returned.
+     */
+    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.
+     */
+    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);
+
+
+protected:
+    /**
+     * Set the indicator of an accepted connection to true.
+     *
+     * @see Completer::handleWaitedResult
+     */
+    virtual void handleWaitedResult(DWORD size);
+
+    friend class LocalServerSocket;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline LocalServerSocketBase& LocalAcceptor::getServerSocket() const
+{
+    return static_cast<LocalServerSocketBase&>(overlappable);
+}
+
+//------------------------------------------------------------------------------
+
+inline LocalSocket* LocalAcceptor::getSocket(Waiter* waiter,
+                                             size_t readingCapacity,
+                                             size_t writingCapacity)
+{
+    if (!accepted) return 0;
+
+    LocalSocket* s = new LocalSocket(waiter, overlappable.releaseHandle(),
+                                     readingCapacity, writingCapacity);
+    accepted = false;
+    return s;
+}
+
+//------------------------------------------------------------------------------
+
+inline LocalSocket* LocalAcceptor::getSocket(size_t readingCapacity,
+                                             size_t writingCapacity)
+{
+    return getSocket(overlappable.getWaiter(),
+                     readingCapacity, writingCapacity);
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_LOCALACCEPTOR_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/LocalClientSocket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/LocalClientSocket.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/LocalClientSocket.h	(revision 9)
@@ -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_WIN32_LOCALCLIENTSOCKET_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_LOCALCLIENTSOCKET_H
+//------------------------------------------------------------------------------
+
+#include "LocalConnector.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A client socket that connects to a named server socket locally,
+ * i.e. a named pipe.
+ *
+ * The server socket's name should be given. The name will be used as
+ * described for LocalServerSocket.
+ */
+class LocalClientSocket : public LocalSocket
+{
+private:
+    /**
+     * The local connector.
+     */
+    LocalConnector connector;
+
+public:
+    /**
+     * Construct the client socket with the given name.
+     */
+    LocalClientSocket(const char* name, Waiter* waiter = 0,
+                      size_t readingCapacity = DEFAULT_CAPACITY,
+                      size_t writingCapacity = DEFAULT_CAPACITY);
+
+    /**
+     * Get the connector.
+     */
+    LocalConnector& getConnector();
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline LocalClientSocket::LocalClientSocket(const char* name, Waiter* waiter,
+                                            size_t readingCapacity,
+                                            size_t writingCapacity) :
+    LocalSocket(waiter, 0, readingCapacity, writingCapacity),
+    connector(this, name)
+{
+}
+
+//------------------------------------------------------------------------------
+
+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_WIN32_LOCALCLIENTSOCKET_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/LocalConnector.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/LocalConnector.cc	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/LocalConnector.cc	(revision 9)
@@ -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 "LocalConnector.h"
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::LocalConnector;
+
+//------------------------------------------------------------------------------
+
+bool LocalConnector::connect()
+{
+    if (connected) return true;
+    if (failed()) return false;
+
+    if (socket.connect(path)) {
+        connected = true;
+        return true;
+    } else {
+        return false;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/LocalConnector.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/LocalConnector.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/LocalConnector.h	(revision 9)
@@ -0,0 +1,138 @@
+// 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_WIN32_LOCALCONNECTOR_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_LOCALCONNECTOR_H
+//------------------------------------------------------------------------------
+
+#include "Completer.h"
+
+#include "LocalSocket.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A connector that connects to a local server socket (i.e. named
+ * pipe).
+ */
+class LocalConnector : public FailableReference<LocalConnector>
+{
+private:
+    /**
+     * The local socket to connect on behalf of which we connect (it should
+     * actually be a LocalClientSocket).
+     */
+    LocalSocket& socket;
+
+    /**
+     * The path of the pipe to connect to.
+     */
+    char path[256];
+
+    /**
+     * Indicate if we are connected.
+     */
+    bool connected;
+
+protected:
+    /**
+     * Construct the connector.
+     */
+    LocalConnector(LocalSocket* socket, const char* name);
+
+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();
+
+private:
+    /**
+     * Get the failable object.
+     */
+    const Failable& getFailable() const;
+
+    /**
+     * Get the failable object.
+     */
+    Failable& getFailable();
+
+    friend class FailableReference<LocalConnector>;
+    friend class LocalClientSocket;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline LocalConnector::LocalConnector(LocalSocket* socket, const char* name) :
+    socket(*socket),
+    connected(false)
+{
+    LocalSocket::setupPath(path, name);
+}
+
+//------------------------------------------------------------------------------
+
+inline const Failable& LocalConnector::getFailable() const
+{
+    return socket;
+}
+
+//------------------------------------------------------------------------------
+
+inline Failable& LocalConnector::getFailable()
+{
+    return socket;
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_LOCALCONNECTOR_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/LocalServerSocket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/LocalServerSocket.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/LocalServerSocket.h	(revision 9)
@@ -0,0 +1,97 @@
+// 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_WIN32_LOCALSERVERSOCKET_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_LOCALSERVERSOCKET_H
+//------------------------------------------------------------------------------
+
+#include "LocalServerSocketBase.h"
+
+#include "LocalAcceptor.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A server socket that works locally, i.e. a named pipe.
+ *
+ * It is identified by a name that should be unique for a user. The
+ * actual pipe will be created with the name \\.\pipe\<name>.
+ */
+class LocalServerSocket : public LocalServerSocketBase
+{
+private:
+    /**
+     * The acceptor to use.
+     */
+    LocalAcceptor acceptor;
+
+public:
+    /**
+     * Construct the socket.
+     */
+    LocalServerSocket(const char* name, Waiter* waiter = 0);
+
+    /**
+     * Get the acceptor.
+     */
+    LocalAcceptor& getAcceptor();
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline LocalServerSocket::LocalServerSocket(const char* name, Waiter* waiter) :
+    LocalServerSocketBase(waiter),
+    acceptor(this, name)
+{
+}
+
+//------------------------------------------------------------------------------
+
+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_WIN32_LOCALSERVERSOCKET_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/LocalServerSocketBase.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/LocalServerSocketBase.cc	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/LocalServerSocketBase.cc	(revision 9)
@@ -0,0 +1,84 @@
+// 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 "LocalServerSocketBase.h"
+
+#include "LocalSocket.h"
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::LocalServerSocketBase;
+
+//------------------------------------------------------------------------------
+
+bool LocalServerSocketBase::createNamedPipe(const char* path)
+{
+    handle = CreateNamedPipe(path, PIPE_ACCESS_DUPLEX |
+                             ((waiter==0) ? 0 : FILE_FLAG_OVERLAPPED),
+                             PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,
+                             PIPE_UNLIMITED_INSTANCES,
+                             BufferedStream::DEFAULT_CAPACITY,
+                             BufferedStream::DEFAULT_CAPACITY,
+                             0, 0);
+    if (handle==0) {
+        setErrorCode(GetLastError());
+    }
+    return handle!=0;
+}
+
+//------------------------------------------------------------------------------
+
+bool LocalServerSocketBase::connectNamedPipe(Overlapped* overlapped)
+{
+    if (overlapped!=0) overlapped->reset();
+    bool result = ConnectNamedPipe(handle,
+                                   (overlapped==0) ? 0 : overlapped->get());
+    DWORD error = GetLastError();
+    if (!result &&
+        (overlapped==0 ||
+         (error!=ERROR_IO_PENDING && error!=ERROR_IO_INCOMPLETE)))
+    {
+        setErrorCode(error);
+        return false;
+    } else if (overlapped==0) {
+        return result;
+    } else {
+        DWORD dummy = 0;
+        return overlapped->getResult(dummy, handle);
+    }
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/LocalServerSocketBase.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/LocalServerSocketBase.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/LocalServerSocketBase.h	(revision 9)
@@ -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_WIN32_LOCALSERVERSOCKETBASE_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_LOCALSERVERSOCKETBASE_H
+//------------------------------------------------------------------------------
+
+#include "Overlappable.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+class Overlapped;
+
+//------------------------------------------------------------------------------
+
+/**
+ * Base class for a local server socket. This is here only to allow
+ * for a more efficient implementation of LocalAcceptor.
+ */
+class LocalServerSocketBase : public Overlappable
+{
+protected:
+    /**
+     * Construct the server socket base.
+     */
+    LocalServerSocketBase(Waiter* waiter);
+
+    /**
+     * Create a new named pipe with the proper settings. The handle of
+     * this object will be set to the created handle.
+     *
+     * @param path the path of the pipe to create. It should be the
+     * final path, not the user-given name.
+     *
+     * @return whether the pipe could be created
+     */
+    bool createNamedPipe(const char* path);
+
+    /**
+     * Connect the named pipe with the current handle of this object.
+     *
+     * @return whether the connection succeeded. If not, it may be a
+     * failure, which is then indicated, or it may be an overlapped
+     * operation which needs to wait.
+     */
+    bool connectNamedPipe(Overlapped* overlapped);
+
+    friend class LocalAcceptor;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline LocalServerSocketBase::LocalServerSocketBase(Waiter* waiter) :
+    Overlappable(waiter)
+{
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_LOCALSERVERSOCKETBASE_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/LocalSocket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/LocalSocket.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/LocalSocket.h	(revision 9)
@@ -0,0 +1,120 @@
+// 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_WIN32_LOCALSOCKET_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_LOCALSOCKET_H
+//------------------------------------------------------------------------------
+
+#include "BufferedStream.h"
+
+#include "Overlapped.h"
+
+#include <cstdio>
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Basically a different name for a buffered stream.
+ */
+class LocalSocket : public BufferedStream
+{
+public:
+    /**
+     * Create a concrete pipe path from the given user-specified name.
+     *
+     * @param dest the destination buffer, which should be at least
+     * 256 bytes long.
+     */
+    static void setupPath(char* dest, const char* name);
+
+protected:
+    /**
+     * Construct the local socket
+     */
+    LocalSocket(Waiter* waiter = 0, HANDLE handle = 0,
+                size_t readingCapacity = DEFAULT_CAPACITY,
+                size_t writingCapacity = DEFAULT_CAPACITY);
+
+
+protected:
+    /**
+     * Connect the client socket to the server.
+     */
+    bool connect(const char* path);
+
+    friend class LocalAcceptor;
+    friend class LocalConnector;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline void LocalSocket::setupPath(char* dest, const char* name)
+{
+    snprintf(dest, 256, "\\\\.\\pipe\\%s", name);
+}
+
+//------------------------------------------------------------------------------
+
+inline LocalSocket::LocalSocket(Waiter* waiter, HANDLE handle,
+                                size_t readingCapacity, size_t writingCapacity):
+    BufferedStream(waiter, handle, readingCapacity, writingCapacity)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline bool LocalSocket::connect(const char* path)
+{
+    handle = CreateFile(path, GENERIC_READ|GENERIC_WRITE,
+                        0, 0, OPEN_EXISTING,
+                        FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, 0);
+    if (handle==0) {
+        setErrorCode(GetLastError());
+    }
+
+    return handle!=0;
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_LOCALSOCKET_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/Makefile.am
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/Makefile.am	(revision 7)
+++ src/hu/varadiistvan/scpl/io/_win32/Makefile.am	(revision 9)
@@ -7,10 +7,30 @@
 libvscpl_io_win32_la_SOURCES=\
         Event.cc                \
-        Waiter.cc
+        Overlapped.cc           \
+        Waiter.cc               \
+        BufferedStream.cc       \
+        ReadingBuffer.cc        \
+        WritingBuffer.cc        \
+        LocalConnector.cc       \
+        LocalAcceptor.cc        \
+        LocalServerSocketBase.cc
 
 include_vscpl_io_win32dir=$(includedir)/hu/varadiistvan/scpl/io/_win32
 include_vscpl_io_win32_HEADERS=\
         EventFailable.h         \
+        Overlappable.h          \
         Event.h                 \
+        Overlapped.h            \
         Waiter.h                \
-        WaitableEvent.h
+        WaitableEvent.h         \
+        BufferedStream.h        \
+        StreamBuffer.h          \
+        ReadingBuffer.h         \
+        WritingBuffer.h         \
+        Completer.h             \
+        LocalSocket.h           \
+        LocalConnector.h        \
+        LocalClientSocket.h     \
+        LocalAcceptor.h         \
+        LocalServerSocketBase.h \
+        LocalServerSocket.h
Index: src/hu/varadiistvan/scpl/io/_win32/Overlappable.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/Overlappable.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/Overlappable.h	(revision 9)
@@ -0,0 +1,146 @@
+// 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_WIN32_OVERLAPPABLE_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_OVERLAPPABLE_H
+//------------------------------------------------------------------------------
+
+#include "EventFailable.h"
+
+#include <windows.h>
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+class Waiter;
+
+//------------------------------------------------------------------------------
+
+/**
+ * Base class for classes that maintain a handle and may be subject to
+ * overlapped I/O operations whose completion is waited for in a
+ * Waiter.
+ */
+class Overlappable : public EventFailable
+{
+protected:
+    /**
+     * The waiter to be used for waiting for events.
+     */
+    Waiter* waiter;
+
+    /**
+     * The handle to use.
+     */
+    HANDLE handle;
+
+protected:
+    /**
+     * Construct the object.
+     */
+    Overlappable(Waiter* waiter = 0, HANDLE handle = 0);
+
+public:
+    /**
+     * Destroy the object.
+     */
+    virtual ~Overlappable();
+
+    /**
+     * Get the waiter.
+     */
+    Waiter* getWaiter();
+
+    /**
+     * Determine if the overlappable has a waiter.
+     */
+    bool hasWaiter() const;
+
+    /**
+     * Get the handle and clear it.
+     */
+    HANDLE releaseHandle();
+
+    friend class Completer;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Overlappable::Overlappable(Waiter* waiter, HANDLE handle) :
+    waiter(waiter),
+    handle(handle)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline Overlappable::~Overlappable()
+{
+    if (handle!=0) CloseHandle(handle);
+}
+
+//------------------------------------------------------------------------------
+
+inline Waiter* Overlappable::getWaiter()
+{
+    return waiter;
+}
+
+//------------------------------------------------------------------------------
+
+inline bool Overlappable::hasWaiter() const
+{
+    return waiter != 0;
+}
+
+//------------------------------------------------------------------------------
+
+inline HANDLE Overlappable::releaseHandle()
+{
+    HANDLE h = handle;
+    handle = 0;
+    return h;
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_OVERLAPPABLE_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/Overlapped.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/Overlapped.cc	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/Overlapped.cc	(revision 9)
@@ -0,0 +1,66 @@
+// 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 "Overlapped.h"
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::Overlapped;
+
+//------------------------------------------------------------------------------
+
+void Overlapped::reset()
+{
+    memset(&overlapped, 0, sizeof(overlapped));
+    overlapped.hEvent = getHandle();
+    clear();
+}
+
+//------------------------------------------------------------------------------
+
+bool Overlapped::getResult(DWORD& size, HANDLE file)
+{
+    bool result = GetOverlappedResult(file, &overlapped, &size, FALSE);
+    if (!result) {
+        DWORD error = GetLastError();
+        if (error!=ERROR_IO_PENDING && error!=ERROR_IO_INCOMPLETE) {
+            setErrorCode(error);
+        }
+    }
+    return result;
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/Overlapped.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/Overlapped.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/Overlapped.h	(revision 9)
@@ -0,0 +1,129 @@
+// 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_WIN32_OVERLAPPED_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_OVERLAPPED_H
+//------------------------------------------------------------------------------
+
+#include "Event.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A wrapper for an OVERLAPPED structure which also has an event
+ * associated with it. Instances of this class can be registered into and
+ * unregistered from a Waiter. The destructor removes the object from
+ * the waiter, if it is registered.
+ */
+class Overlapped : public Event
+{
+private:
+    /**
+     * The Windows OVERLAPPED structure.
+     */
+    OVERLAPPED overlapped;
+
+public:
+    /**
+     * Construct the object. The overlapped structure will be reset to
+     * 0, and the event handle will be set.
+     */
+    Overlapped(EventFailable& eventFailable);
+
+    /**
+     * Reset the overlapped structure and set its event handle. The
+     * event is also cleared.
+     */
+    void reset();
+
+    /**
+     * Get the pointer to the overlapped structure.
+     */
+    OVERLAPPED* get();
+
+    /**
+     * Get the pointer to the overlapped structure.
+     */
+    const OVERLAPPED* get() const;
+
+    /**
+     * Get the result of the overlapped operation.
+     *
+     * If the operation has completed, the event will be cleared.
+     *
+     * @param size on successful return, it will contain the number of
+     * bytes read or written, which may be 0 for an end-of-file
+     * condition
+     * @param file the handle of the object on which the operation in
+     * question was performed
+     *
+     * @return true if the operation has completed, or false if it has
+     * not, or a failure has occured.
+     */
+    bool getResult(DWORD& size, HANDLE file);
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Overlapped::Overlapped(EventFailable& eventFailable) :
+    Event(eventFailable)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline OVERLAPPED* Overlapped::get()
+{
+    return &overlapped;
+}
+
+//------------------------------------------------------------------------------
+
+inline const OVERLAPPED* Overlapped::get() const
+{
+    return &overlapped;
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_OVERLAPPED_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/ReadingBuffer.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/ReadingBuffer.cc	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/ReadingBuffer.cc	(revision 9)
@@ -0,0 +1,77 @@
+// 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 "ReadingBuffer.h"
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::ReadingBuffer;
+
+//------------------------------------------------------------------------------
+
+bool ReadingBuffer::read()
+{
+    if (failed()) return false;
+
+    if (getLength()>0) {
+        return true;
+    }
+
+    bool result = false;
+    if (checkWaitedResult(result)) {
+        return result;
+    }
+
+    BufferedStream& stream = getStream();
+    ssize_t numRead = stream.read(getData(), getCapacity(), overlapped);
+    if (numRead<0) {
+        if (!stream.failed()) {
+            addTo(stream.getWaiter());
+        }
+    } else {
+        addLength(numRead);
+    }
+    return numRead>=0;
+}
+
+//------------------------------------------------------------------------------
+
+void ReadingBuffer::handleWaitedResult(DWORD size)
+{
+    addLength(size);
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/ReadingBuffer.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/ReadingBuffer.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/ReadingBuffer.h	(revision 9)
@@ -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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_WIN32_READINGBUFFER_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_READINGBUFFER_H
+//------------------------------------------------------------------------------
+
+#include "StreamBuffer.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A buffer used for reading from a stream buffer.
+ *
+ * It should be made empty, and then the function read() should be
+ * called on it. If it returns true, some data could be read. If the
+ * amount of data in the buffer is then 0, that indicates and
+ * end-of-file condition.
+ */
+class ReadingBuffer : public StreamBuffer
+{
+protected:
+    /**
+     * Construct the buffer.
+     */
+    ReadingBuffer(size_t capacity, BufferedStream* stream);
+
+public:
+    /**
+     * Read into the buffer using the buffered stream if possible.
+     *
+     * If the buffer contains data, this function returns immediately
+     * with success, so the buffer should be reset before reading.
+     *
+     * If some data can be read immediately, that is stored in the
+     * buffer, and success is indicated. Success is indicated even if
+     * the amount of data read is 0, allowing for signalling the
+     * end-of-file or end-of-connection condition.
+     *
+     * If the reading operation would block, the stream is set up so
+     * that it would read, and failure is returned.
+     *
+     * Otherwise, if the reading operation fails for some other
+     * reason, the buffer's error code is set, so it should always be
+     * checked on a failure!
+     */
+    bool read();
+
+protected:
+    /**
+     * Set the buffer's length to the given value.
+     *
+     * @see Completer::handleWaitedResult
+     */
+    virtual void handleWaitedResult(DWORD size);
+
+    friend class BufferedStream;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline ReadingBuffer::ReadingBuffer(size_t capacity, BufferedStream* stream) :
+    StreamBuffer(capacity, stream)
+{
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_READINGBUFFER_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/StreamBuffer.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/StreamBuffer.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/StreamBuffer.h	(revision 9)
@@ -0,0 +1,93 @@
+// 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_WIN32_STREAMBUFFER_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_STREAMBUFFER_H
+//------------------------------------------------------------------------------
+
+#include "../Buffer.h"
+#include "Completer.h"
+
+#include "BufferedStream.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Base class for stream reading and writing buffers.
+ */
+class StreamBuffer : public Buffer, public Completer
+{
+protected:
+    /**
+     * Construct the stream buffer with the given capacity and for the
+     * given stream.
+     */
+    StreamBuffer(size_t capacity, BufferedStream* stream);
+
+    /**
+     * Get the stream.
+     *
+     * This just casts the overlappable of the Completer part knowing
+     * that it must be a BufferedStream
+     */
+    BufferedStream& getStream() const;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline StreamBuffer::StreamBuffer(size_t capacity, BufferedStream* stream) :
+    Buffer(capacity),
+    Completer(stream)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline BufferedStream& StreamBuffer::getStream() const
+{
+    return static_cast<BufferedStream&>(overlappable);
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_STREAMBUFFER_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/WritingBuffer.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/WritingBuffer.cc	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/WritingBuffer.cc	(revision 9)
@@ -0,0 +1,76 @@
+// 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 "WritingBuffer.h"
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::WritingBuffer;
+
+//------------------------------------------------------------------------------
+
+bool WritingBuffer::write()
+{
+    if (failed()) return false;
+
+    if (getLength()==0) {
+        return true;
+    }
+
+    bool result;
+    if (checkWaitedResult(result)) {
+        return result;
+    }
+
+    BufferedStream& stream = getStream();
+    result = stream.write(getData(), getLength(), overlapped);
+    if (result) {
+        reset();
+    } else if (!stream.failed()) {
+        addTo(stream.getWaiter());
+    }
+
+    return result;
+}
+
+//------------------------------------------------------------------------------
+
+void WritingBuffer::handleWaitedResult(DWORD /*size*/)
+{
+    reset();
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/WritingBuffer.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/WritingBuffer.h	(revision 9)
+++ src/hu/varadiistvan/scpl/io/_win32/WritingBuffer.h	(revision 9)
@@ -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.
+
+#ifndef HU_VARADIISTVAN_SCPL_IO_WIN32_WRITINGBUFFER_H
+#define HU_VARADIISTVAN_SCPL_IO_WIN32_WRITINGBUFFER_H
+//------------------------------------------------------------------------------
+
+#include "StreamBuffer.h"
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A buffer used for writing into a buffered stream.
+ *
+ * The data to write should be stored in the buffer. Then write()
+ * should be called. If it returns true, it indicates that all data
+ * has been written. In that case the buffer is automatically emptied.
+ */
+class WritingBuffer : public StreamBuffer
+{
+protected:
+    /**
+     * Construct the buffer.
+     */
+    WritingBuffer(size_t capacity, BufferedStream* stream);
+
+public:
+    /**
+     * Write the contents of the buffer using the associated buffered
+     * stream.
+     *
+     * If the buffer is empty, the function returns indicating
+     * success.
+     *
+     * If the complete remaining contents could be written, it also indicates
+     * success, and the buffer is reset, ready to be used again.
+     *
+     * If not everything can be written and the write operation
+     * indicates that it would block, this function returns failure
+     * after the stream has been set up  to handle the corresponding
+     * poll events.
+     *
+     * Otherwise, if the writing operation fails for some other
+     * reason, the buffer's error code is set to the error's code and
+     * false is returned.
+     */
+    bool write();
+
+protected:
+    /**
+     * Reset the buffer to signify that its contents have been written.
+     *
+     * @see Completer::handleWaitedResult
+     */
+    virtual void handleWaitedResult(DWORD size);
+
+    friend class BufferedStream;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline WritingBuffer::WritingBuffer(size_t capacity, BufferedStream* stream) :
+    StreamBuffer(capacity, stream)
+{
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+#endif // HU_VARADIISTVAN_SCPL_IO_WIN32_WRITINGBUFFER_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
