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 28)
@@ -40,7 +40,8 @@
 //------------------------------------------------------------------------------
 
-BufferedStream::BufferedStream(Waiter* waiter, HANDLE handle,
+BufferedStream::BufferedStream(std::unique_ptr<EventFactory> eventFactory,
+                               Waiter* waiter, HANDLE handle,
                                size_t readingCapacity, size_t writingCapacity) :
-    Overlappable(waiter, handle),
+    Overlappable(std::move(eventFactory), waiter, handle),
     readingBuffer( (readingCapacity==0) ? 0 :
                    new ReadingBuffer(readingCapacity, this)),
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 28)
@@ -76,5 +76,6 @@
      * Construct the buffered stream.
      */
-    BufferedStream(Waiter* waiter = 0, HANDLE handle = 0,
+    BufferedStream(std::unique_ptr<EventFactory> eventFactory,
+                   Waiter* waiter = 0, HANDLE handle = 0,
                    size_t readingCapacity = DEFAULT_CAPACITY,
                    size_t writingCapacity = DEFAULT_CAPACITY);
Index: src/hu/varadiistvan/scpl/io/_win32/Event.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/Event.h	(revision 6)
+++ src/hu/varadiistvan/scpl/io/_win32/Event.h	(revision 28)
@@ -133,5 +133,5 @@
 inline Event::Event(EventFailable& eventFailable) :
     eventFailable(eventFailable),
-    handle(CreateEvent(0, true, false, 0)),
+    handle(eventFailable.createEvent()),
     waiter(0)
 {
@@ -144,5 +144,5 @@
 {
     removeFromWaiter();
-    CloseHandle(handle);
+    eventFailable.destroyEvent(handle);
 }
 
@@ -172,5 +172,5 @@
 inline void Event::fire()
 {
-    if (!SetEvent(handle)) {
+    if (!eventFailable.setEvent(handle)) {
         eventFailable.setErrorCode(GetLastError());
     }
@@ -181,5 +181,5 @@
 inline bool Event::clear()
 {
-    if (!ResetEvent(handle)) {
+    if (!eventFailable.resetEvent(handle)) {
         eventFailable.setErrorCode(GetLastError());
         return false;
Index: src/hu/varadiistvan/scpl/io/_win32/EventFactory.cc
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/EventFactory.cc	(revision 28)
+++ src/hu/varadiistvan/scpl/io/_win32/EventFactory.cc	(revision 28)
@@ -0,0 +1,72 @@
+// Copyright (c) 2022 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 "EventFactory.h"
+
+//------------------------------------------------------------------------------
+
+using hu::varadiistvan::scpl::io::EventFactory;
+
+//------------------------------------------------------------------------------
+
+HANDLE EventFactory::createEvent()
+{
+    auto event = CreateEvent(0, true, false, 0);
+    return event;
+}
+
+//------------------------------------------------------------------------------
+
+bool EventFactory::setEvent(HANDLE handle)
+{
+    return SetEvent(handle);
+}
+
+//------------------------------------------------------------------------------
+
+bool EventFactory::resetEvent(HANDLE handle)
+{
+    return ResetEvent(handle);
+}
+
+//------------------------------------------------------------------------------
+
+void EventFactory::destroyEvent(HANDLE handle)
+{
+    CloseHandle(handle);
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/EventFactory.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/EventFactory.h	(revision 28)
+++ src/hu/varadiistvan/scpl/io/_win32/EventFactory.h	(revision 28)
@@ -0,0 +1,92 @@
+// Copyright (c) 2022 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.
+
+#pragma once
+
+//------------------------------------------------------------------------------
+
+#include <windows.h>
+
+//------------------------------------------------------------------------------
+
+namespace hu { namespace varadiistvan { namespace scpl { namespace io {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Base class for event factories. This one creates and handles standard
+ * Windows events.
+ */
+class EventFactory
+{
+public:
+    /**
+     * Virtual destructor.
+     */
+    virtual ~EventFactory() = default;
+
+    /**
+     * Create an event for this object.
+     *
+     * This default implementation calls CreateEvent().
+     */
+    virtual HANDLE createEvent();
+
+    /**
+     * Set the event represented by the given handle.
+     *
+     * This default implementation calls SetEvent().
+     */
+    virtual bool setEvent(HANDLE handle);
+
+    /**
+     * Set the event represented by the given handle.
+     *
+     * This default implementation calls ResetEvent().
+     */
+    virtual bool resetEvent(HANDLE handle);
+
+    /**
+     * Destroy the event represented by the given handle.
+     *
+     * This default implementation calls CloseHandle().
+     */
+    virtual void destroyEvent(HANDLE handle);
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace hu::varadiistvan::scpl::io */ } /* namespace hu::varadiistvan::scpl */ } /* namespace hu::varadiistvan */ } /* namespace hu */
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/hu/varadiistvan/scpl/io/_win32/EventFailable.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/EventFailable.h	(revision 6)
+++ src/hu/varadiistvan/scpl/io/_win32/EventFailable.h	(revision 28)
@@ -33,4 +33,8 @@
 #include "../Failable.h"
 
+#include "EventFactory.h"
+
+#include <memory>
+
 //------------------------------------------------------------------------------
 
@@ -51,6 +55,75 @@
 class EventFailable : public Failable
 {
+protected:
+    /**
+     * The event factory for this object.
+     */
+    std::unique_ptr<EventFactory> eventFactory;
+
+protected:
+    /**
+     * Construct the object with the given event factory.
+     */
+    EventFailable(std::unique_ptr<EventFactory> eventFactory);
+
+    /**
+     * Create an event for this object using the event factory.
+     */
+    HANDLE createEvent();
+
+    /**
+     * Set the event represented by the given handle using the event factory.
+     */
+    bool setEvent(HANDLE handle);
+
+    /**
+     * Set the event represented by the given handle using the event factory.
+     */
+    bool resetEvent(HANDLE handle);
+
+    /**
+     * Destroy the event represented by the given handle using the event factory.
+     */
+    void destroyEvent(HANDLE handle);
+
     friend class Event;
 };
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline EventFailable::EventFailable(std::unique_ptr<EventFactory> eventFactory) :
+    eventFactory(std::move(eventFactory))
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline HANDLE EventFailable::createEvent()
+{
+    return eventFactory->createEvent();
+}
+
+//------------------------------------------------------------------------------
+
+inline bool EventFailable::setEvent(HANDLE handle)
+{
+    return eventFactory->setEvent(handle);
+}
+
+//------------------------------------------------------------------------------
+
+inline bool EventFailable::resetEvent(HANDLE handle)
+{
+    return eventFactory->resetEvent(handle);
+}
+
+//------------------------------------------------------------------------------
+
+inline void EventFailable::destroyEvent(HANDLE handle)
+{
+    eventFactory->destroyEvent(handle);
+}
 
 //------------------------------------------------------------------------------
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 28)
@@ -83,5 +83,5 @@
 
 inline LocalServerSocketBase::LocalServerSocketBase(Waiter* waiter) :
-    Overlappable(waiter)
+    Overlappable(std::make_unique<EventFactory>(), waiter)
 {
 }
Index: src/hu/varadiistvan/scpl/io/_win32/LocalSocket.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/LocalSocket.h	(revision 14)
+++ src/hu/varadiistvan/scpl/io/_win32/LocalSocket.h	(revision 28)
@@ -89,5 +89,6 @@
 inline LocalSocket::LocalSocket(Waiter* waiter, HANDLE handle,
                                 size_t readingCapacity, size_t writingCapacity):
-    BufferedStream(waiter, handle, readingCapacity, writingCapacity)
+    BufferedStream(std::make_unique<EventFactory>(),
+                   waiter, handle, readingCapacity, writingCapacity)
 {
 }
Index: src/hu/varadiistvan/scpl/io/_win32/Makefile.am
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/Makefile.am	(revision 25)
+++ src/hu/varadiistvan/scpl/io/_win32/Makefile.am	(revision 28)
@@ -7,4 +7,5 @@
 libvscpl_io_win32_la_SOURCES=\
         Event.cc                \
+	EventFactory.cc		\
         Overlapped.cc           \
         Waiter.cc               \
@@ -18,4 +19,5 @@
 include_vscpl_io_win32dir=$(includedir)/hu/varadiistvan/scpl/io/_win32
 include_vscpl_io_win32_HEADERS=\
+	EventFactory.h		\
         EventFailable.h         \
         Overlappable.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 28)
@@ -67,5 +67,6 @@
      * Construct the object.
      */
-    Overlappable(Waiter* waiter = 0, HANDLE handle = 0);
+    Overlappable(std::unique_ptr<EventFactory> eventFactory,
+                 Waiter* waiter = 0, HANDLE handle = 0);
 
 public:
@@ -97,5 +98,7 @@
 //------------------------------------------------------------------------------
 
-inline Overlappable::Overlappable(Waiter* waiter, HANDLE handle) :
+inline Overlappable::Overlappable(std::unique_ptr<EventFactory> eventFactory,
+                                  Waiter* waiter, HANDLE handle) :
+    EventFailable(std::move(eventFactory)),
     waiter(waiter),
     handle(handle)
Index: src/hu/varadiistvan/scpl/io/_win32/WaitableEvent.h
===================================================================
--- src/hu/varadiistvan/scpl/io/_win32/WaitableEvent.h	(revision 7)
+++ src/hu/varadiistvan/scpl/io/_win32/WaitableEvent.h	(revision 28)
@@ -41,5 +41,5 @@
  * An event which can be waited for.
  */
-class WaitableEvent : public Event, public EventFailable
+class WaitableEvent : public EventFailable, public Event
 {
 public:
@@ -61,4 +61,5 @@
 
 inline WaitableEvent::WaitableEvent(Waiter* waiter) :
+    EventFailable(std::make_unique<EventFactory>()),
     Event(static_cast<EventFailable&>(*this))
 {
