Index: src/xplcommon/Makefile.am
===================================================================
--- src/xplcommon/Makefile.am	(revision 3)
+++ src/xplcommon/Makefile.am	(revision 4)
@@ -22,3 +22,5 @@
 include_xplcommon_HEADERS=\
 	config.h	\
-	Thread.h
+	Thread.h	\
+	Waiter.h	\
+	WaitableEvent.h
Index: src/xplcommon/WaitableEvent.h
===================================================================
--- src/xplcommon/WaitableEvent.h	(revision 4)
+++ src/xplcommon/WaitableEvent.h	(revision 4)
@@ -0,0 +1,67 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+#ifndef XPLCOMMON_WAITABLEEVENT_H
+#define XPLCOMMON_WAITABLEEVENT_H
+//------------------------------------------------------------------------------
+
+#include "config.h"
+
+//------------------------------------------------------------------------------
+
+#if TARGET_API_WIN32
+
+//------------------------------------------------------------------------------
+
+// #include "win32/WaitableEvent.h"
+
+// namespace xplcommon { typedef win32::WaitableEvent WaitableEvent; }
+
+//------------------------------------------------------------------------------
+
+#else // TARGET_API_WIN32
+
+//------------------------------------------------------------------------------
+
+#include "posix/WaitableEvent.h"
+
+namespace xplcommon { typedef posix::WaitableEvent WaitableEvent; }
+
+//------------------------------------------------------------------------------
+
+#endif // TARGET_API_WIN32
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_WAITABLEEVENT_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/Waiter.h
===================================================================
--- src/xplcommon/Waiter.h	(revision 4)
+++ src/xplcommon/Waiter.h	(revision 4)
@@ -0,0 +1,67 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+#ifndef XPLCOMMON_WAITER_H
+#define XPLCOMMON_WAITER_H
+//------------------------------------------------------------------------------
+
+#include "config.h"
+
+//------------------------------------------------------------------------------
+
+#if TARGET_API_WIN32
+
+//------------------------------------------------------------------------------
+
+// #include "win32/Waiter.h"
+
+// namespace xplcommon { typedef win32::Waiter Waiter; }
+
+//------------------------------------------------------------------------------
+
+#else // TARGET_API_WIN32
+
+//------------------------------------------------------------------------------
+
+#include "posix/Waiter.h"
+
+namespace xplcommon { typedef posix::Waiter Waiter; }
+
+//------------------------------------------------------------------------------
+
+#endif // TARGET_API_WIN32
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_WAITER_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/posix/Makefile.am
===================================================================
--- src/xplcommon/posix/Makefile.am	(revision 3)
+++ src/xplcommon/posix/Makefile.am	(revision 4)
@@ -4,5 +4,6 @@
 	Thread.cc		\
 	Waitable.cc	\
-	Waiter.cc
+	Waiter.cc	\
+	WaitableEvent.cc
 
 include_xplcommon_posixdir=$(includedir)/xplcommon/posix
@@ -10,3 +11,4 @@
 	Thread.h		\
 	Waitable.h		\
-	Waiter.h
+	Waiter.h		\
+	WaitableEvent.h
Index: src/xplcommon/posix/Thread.h
===================================================================
--- src/xplcommon/posix/Thread.h	(revision 3)
+++ src/xplcommon/posix/Thread.h	(revision 4)
@@ -33,4 +33,5 @@
 
 #include <pthread.h>
+#include <unistd.h>
 
 //------------------------------------------------------------------------------
@@ -45,4 +46,10 @@
 class Thread
 {
+public:
+    /**
+     * Sleep for the given number of milliseconds.
+     */
+    static void sleep(unsigned millis);
+
 private:
     /**
@@ -84,4 +91,11 @@
 //------------------------------------------------------------------------------
 
+inline void Thread::sleep(unsigned millis)
+{
+    usleep(static_cast<useconds_t>(millis)*1000);
+}
+
+//------------------------------------------------------------------------------
+
 inline Thread::~Thread()
 {
Index: src/xplcommon/posix/Waitable.cc
===================================================================
--- src/xplcommon/posix/Waitable.cc	(revision 3)
+++ src/xplcommon/posix/Waitable.cc	(revision 4)
@@ -34,7 +34,16 @@
 #include "Waiter.h"
 
+#include <fcntl.h>
+
 //------------------------------------------------------------------------------
 
 using xplcommon::posix::Waitable;
+
+//------------------------------------------------------------------------------
+
+void Waitable::setNonBlocking(int fd)
+{
+    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+}
 
 //------------------------------------------------------------------------------
Index: src/xplcommon/posix/Waitable.h
===================================================================
--- src/xplcommon/posix/Waitable.h	(revision 3)
+++ src/xplcommon/posix/Waitable.h	(revision 4)
@@ -47,4 +47,10 @@
 class Waitable
 {
+public:
+    /**
+     * Set the given file descriptor to non-blocking.
+     */
+    static void setNonBlocking(int fd);
+
 protected:
     /**
Index: src/xplcommon/posix/WaitableEvent.cc
===================================================================
--- src/xplcommon/posix/WaitableEvent.cc	(revision 4)
+++ src/xplcommon/posix/WaitableEvent.cc	(revision 4)
@@ -0,0 +1,118 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+//------------------------------------------------------------------------------
+
+#include "WaitableEvent.h"
+
+#include <cassert>
+#include <cerrno>
+#include <cstdio>
+
+#include <poll.h>
+#include <unistd.h>
+
+#include <sys/eventfd.h>
+
+//------------------------------------------------------------------------------
+
+using xplcommon::posix::WaitableEvent;
+
+//------------------------------------------------------------------------------
+
+WaitableEvent::WaitableEvent(Waiter* waiter) :
+    Waitable(waiter, eventfd(0, EFD_NONBLOCK), POLLIN)
+{
+    assert(fd>=0);
+}
+
+//------------------------------------------------------------------------------
+
+WaitableEvent::~WaitableEvent()
+{
+    close(fd);
+}
+
+//------------------------------------------------------------------------------
+
+bool WaitableEvent::ready()
+{
+    return fired;
+}
+
+//------------------------------------------------------------------------------
+
+void WaitableEvent::fire()
+{
+    static const uint64_t one = 1;
+    if (write(fd, &one, sizeof(one))<0) {
+        if (errno!=EAGAIN) {
+            perror("xplcommon::posix::WaitableEvent::fire: write");
+            assert(0);
+        }
+    }
+}
+
+//------------------------------------------------------------------------------
+
+bool WaitableEvent::check()
+{
+    if (fired) {
+        fired = false;
+        return true;
+    } else {
+        return false;
+    }
+}
+
+//------------------------------------------------------------------------------
+
+void WaitableEvent::handleEvents(short events)
+{
+    if ((events&POLLIN)==POLLIN) {
+        uint64_t value = 0;
+        if (read(fd, &value, sizeof(value))<0) {
+            if (errno!=EAGAIN) {
+                perror("xplcommon::posix::WaitableEvent::handleEvents: read");
+                assert(0);
+            }
+        } else {
+            fired = value>0;
+        }
+    }
+}
+
+//------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplcommon/posix/WaitableEvent.h
===================================================================
--- src/xplcommon/posix/WaitableEvent.h	(revision 4)
+++ src/xplcommon/posix/WaitableEvent.h	(revision 4)
@@ -0,0 +1,98 @@
+// Copyright (c) 2012 by István Váradi
+
+// This file is part of libxplcommon, a common utility library for
+// development related to X-Plane
+
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+
+// 1. Redistributions of source code must retain the above copyright notice, this
+//    list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+//    this list of conditions and the following disclaimer in the documentation
+//    and/or other materials provided with the distribution.
+
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// The views and conclusions contained in the software and documentation are those
+// of the authors and should not be interpreted as representing official policies,
+// either expressed or implied, of the FreeBSD Project.
+
+#ifndef XPLCOMMON_POSIX_WAITABLEEVENT_H
+#define XPLCOMMON_POSIX_WAITABLEEVENT_H
+//------------------------------------------------------------------------------
+
+#include "Waitable.h"
+
+//------------------------------------------------------------------------------
+
+namespace xplcommon { namespace posix {
+
+//------------------------------------------------------------------------------
+
+/**
+ * An event on which one can wait with a waiter.
+ */
+class WaitableEvent : public Waitable
+{
+private:
+    /**
+     * Indicate if the event is fired.
+     */
+    volatile bool fired;
+
+public:
+    /**
+     * Construct the event.
+     */
+    WaitableEvent(Waiter* waiter = 0);
+
+    /**
+     * Destroy the event.
+     */
+    virtual ~WaitableEvent();
+
+    /**
+     * Check if the event is fired or not.
+     */
+    virtual bool ready();
+
+    /**
+     * Fire the event.
+     */
+    void fire();
+
+    /**
+     * Check if the event is fired or not. If so, the fired status
+     * will be cleared.
+     */
+    bool check();
+
+protected:
+    /**
+     * Handle the given events.
+     */
+    virtual void handleEvents(short events);
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplcommon::posix */ } /* namespace xplcommon */
+
+//------------------------------------------------------------------------------
+#endif // XPLCOMMON_POSIX_WAITABLEEVENT_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
