Index: src/xplra/ListenThread.cc
===================================================================
--- src/xplra/ListenThread.cc	(revision 1)
+++ src/xplra/ListenThread.cc	(revision 2)
@@ -31,4 +31,8 @@
 #include "ListenThread.h"
 
+#include "ServerThread.h"
+
+#include <xplcommon/LocalServerSocket.h>
+#include <xplcommon/LocalAcceptor.h>
 #include <xplcommon/Util.h>
 
@@ -37,4 +41,6 @@
 using xplra::ListenThread;
 
+using xplcommon::LocalServerSocket;
+using xplcommon::LocalAcceptor;
 using xplcommon::Util;
 
@@ -45,7 +51,15 @@
     Util::debug("xplra::ListenThread::run: started\n");
 
-    while(!quitEvent.check() && !quitEvent.failed()) {
+    LocalServerSocket socket("xplra", &waiter);
+    LocalAcceptor& acceptor = socket.getAcceptor();
+    while(!quitEvent.check() && !quitEvent.failed() && !acceptor.failed()) {
+        if (acceptor.accept()) {
+            ServerThread* serverThread = new ServerThread(acceptor);
+            serverThread->start();
+        }
         waiter.wait();
     }
+
+    ServerThread::quitAll();
 
     Util::debug("xplra::ListenThread::run: quitting\n");
Index: src/xplra/ListenThread.h
===================================================================
--- src/xplra/ListenThread.h	(revision 0)
+++ src/xplra/ListenThread.h	(revision 2)
@@ -31,4 +31,6 @@
 //------------------------------------------------------------------------------
 
+#include "RequestQueue.h"
+
 #include <xplcommon/Thread.h>
 #include <xplcommon/Waiter.h>
@@ -60,4 +62,9 @@
      */
     xplcommon::WaitableEvent quitEvent;
+
+    /**
+     * The queue for the requests.
+     */
+    RequestQueue requestQueue;
 
 public:
@@ -92,4 +99,5 @@
 inline void ListenThread::quit()
 {
+    requestQueue.disable();
     quitEvent.fire();
 }
Index: src/xplra/Makefile.am
===================================================================
--- src/xplra/Makefile.am	(revision 1)
+++ src/xplra/Makefile.am	(revision 2)
@@ -3,6 +3,8 @@
 AM_CXXFLAGS=$(LIBXPLCOMMON_CFLAGS)
 
+AM_CPPFLAGS=-DXPLM210
+
 if TARGET_API_WIN32
-AM_CPPFLAGS=-DIBM
+AM_CPPFLAGS+=-DIBM
 AM_LDFLAGS=@XPSDK_LDFLAGS@ -no-undefined
 if TARGET_API_WIN64
@@ -14,7 +16,8 @@
 
 if TARGET_API_POSIX
-AM_CPPFLAGS=-DLIN
+AM_CPPFLAGS+=-DLIN
 AM_CXXFLAGS+=-fPIC -fno-stack-protector
 endif
+
 
 lib_LTLIBRARIES=libxplra.la
@@ -22,8 +25,13 @@
 libxplra_la_SOURCES= \
 	plugin.cc	\
-	ListenThread.cc
+	ListenThread.cc	\
+	RequestQueue.cc	\
+	ServerThread.cc
 
 libxplra_la_LIBADD=$(LIBXPLCOMMON_LIBS)
 
 noinst_HEADERS= \
-	ListenThread.h
+	ListenThread.h		\
+	Request.h		\
+	RequestQueue.h		\
+	ServerThread.h
Index: src/xplra/Request.h
===================================================================
--- src/xplra/Request.h	(revision 2)
+++ src/xplra/Request.h	(revision 2)
@@ -0,0 +1,94 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of XPLRA, a remote-access plugin for 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 XPLRA_REQUEST_H
+#define XPLRA_REQUEST_H
+//------------------------------------------------------------------------------
+
+namespace xplra {
+
+//------------------------------------------------------------------------------
+
+/**
+ * Base class for requests. A request is something that is executed in
+ * the flight loop.
+ */
+class Request
+{
+private:
+    /**
+     * Indicate that the request is completed.
+     */
+    volatile bool completed;
+
+public:
+    /**
+     * Construct the request.
+     */
+    Request();
+
+    /**
+     * Virtual destructor.
+     */
+    virtual ~Request();
+
+    /**
+     * Execute the request. Make this very fast!
+     */
+    virtual void execute() = 0;
+
+    friend class RequestQueue;
+};
+
+//------------------------------------------------------------------------------
+// Inline definitions
+//------------------------------------------------------------------------------
+
+inline Request::Request() :
+    completed(false)
+{
+}
+
+//------------------------------------------------------------------------------
+
+inline Request::~Request()
+{
+}
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplra */
+
+//------------------------------------------------------------------------------
+#endif // XPLRA_REQUEST_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplra/RequestQueue.cc
===================================================================
--- src/xplra/RequestQueue.cc	(revision 2)
+++ src/xplra/RequestQueue.cc	(revision 2)
@@ -0,0 +1,156 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of XPLRA, a remote-access plugin for 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 "RequestQueue.h"
+
+#include "Request.h"
+
+#include <xplcommon/Util.h>
+
+//------------------------------------------------------------------------------
+
+using xplra::RequestQueue;
+
+using xplcommon::Util;
+
+//------------------------------------------------------------------------------
+
+float RequestQueue::flightLoop(float /*inElapsedSinceLastCall*/,
+                               float /*inElapsedTimeSinceLastFlightLoop*/,
+                               int /*inCounter*/, void* inRefCon)
+{
+    RequestQueue* requestQueue = reinterpret_cast<RequestQueue*>(inRefCon);
+    requestQueue->run();
+#if USE_SCHEDULE_FLIGHTLOOP
+    return 0.0;
+#else
+    return flightLoopInterval;
+#endif
+}
+
+//------------------------------------------------------------------------------
+
+RequestQueue::RequestQueue() :
+    enabled(true)
+{
+#if USE_SCHEDULE_FLIGHTLOOP
+    XPLMCreateFlightLoop_t createFL;
+
+    createFL.structSize = sizeof(createFL);
+    createFL.phase = xplm_FlightLoop_Phase_AfterFlightModel;
+    createFL.callbackFunc = &flightLoop;
+    createFL.refcon = this;
+
+    flightLoopID = XPLMCreateFlightLoop(&createFL);
+#else
+    XPLMRegisterFlightLoopCallback(&flightLoop, flightLoopInterval, this);
+#endif
+}
+
+//------------------------------------------------------------------------------
+
+bool RequestQueue::execute(Request* request)
+{
+    mutex.lock();
+    if (!enabled) {
+        mutex.unlock();
+        return false;
+    }
+
+    request->completed = false;
+    requests.push_back(request);
+
+#if USE_SCHEDULE_FLIGHTLOOP
+    if (requests.size()==1) {
+        XPLMScheduleFlightLoop(flightLoopID, -2.0, true);
+    }
+#endif
+
+    while(enabled && !request->completed) {
+        requestsDone.wait(mutex);
+    }
+
+    bool result = request->completed;
+
+    mutex.unlock();
+
+    return result;
+}
+
+//------------------------------------------------------------------------------
+
+void RequestQueue::disable()
+{
+    mutex.lock();
+    enabled = false;
+    mutex.unlock();
+    requestsDone.broadcast();
+#if USE_SCHEDULE_FLIGHTLOOP
+    XPLMDestroyFlightLoop(flightLoopID);
+#else
+    XPLMUnregisterFlightLoopCallback(&flightLoop, this);
+#endif
+}
+
+//------------------------------------------------------------------------------
+
+void RequestQueue::run()
+{
+    requests_t queuedRequests;
+
+    mutex.lock();
+    requests.swap(queuedRequests);
+    mutex.unlock();
+
+    if (queuedRequests.empty()) return;
+
+    for(requests_t::const_iterator i = queuedRequests.begin();
+        i!=queuedRequests.end(); ++i)
+    {
+        (*i)->execute();
+    }
+
+    mutex.lock();
+    for(requests_t::const_iterator i = queuedRequests.begin();
+        i!=queuedRequests.end(); ++i)
+    {
+        (*i)->completed = true;
+    }
+    mutex.unlock();
+    requestsDone.broadcast();
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplra/RequestQueue.h
===================================================================
--- src/xplra/RequestQueue.h	(revision 2)
+++ src/xplra/RequestQueue.h	(revision 2)
@@ -0,0 +1,168 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of XPLRA, a remote-access plugin for 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 XPLRA_REQUESTQUEUE_H
+#define XPLRA_REQUESTQUEUE_H
+//------------------------------------------------------------------------------
+
+#include <xplcommon/Mutex.h>
+#include <xplcommon/CondVar.h>
+
+#include <XPLMProcessing.h>
+
+#include <vector>
+
+//------------------------------------------------------------------------------
+
+// Define to 1, if the new XPLMScheduleFlightLoop function should be
+// used to schedule the flight loop only on-demand
+#define USE_SCHEDULE_FLIGHTLOOP 0
+
+//------------------------------------------------------------------------------
+
+namespace xplra {
+
+//------------------------------------------------------------------------------
+
+class Request;
+
+//------------------------------------------------------------------------------
+
+/**
+ * The queue of the requests. Client serving threads can add requests
+ * to the queue. The queue provides a flight loop callback, which it
+ * automatically schedules if a request is added to it, unless we are
+ * already disabled.
+ *
+ * An instance of the queue should be created in the plugin enable
+ * callback. The disable callback should disable the queue, so that it
+ * will not accept any further requests.
+ */
+class RequestQueue
+{
+private:
+    /**
+     * Type for the collection of the queued requests.
+     */
+    typedef std::vector<Request*> requests_t;
+
+#if !USE_SCHEDULE_FLIGHTLOOP
+    /**
+     * The interval of the flight loop.
+     */
+    static const float flightLoopInterval = 0.1;
+#endif
+
+    /**
+     * The flight loop function.
+     */
+    static float flightLoop(float inElapsedSinceLastCall,
+                            float inElapsedTimeSinceLastFlightLoop,
+                            int inCounter, void* inRefCon);
+
+#if USE_SCHEDULE_FLIGHTLOOP
+    /**
+     * The ID of the flight loop running the queue.
+     */
+    XPLMFlightLoopID flightLoopID;
+#endif
+
+    /**
+     * The mutex protecting the queue.
+     */
+    xplcommon::Mutex mutex;
+
+    /**
+     * A conditional variable to notify the threads waiting for their
+     * request to be executed.
+     */
+    xplcommon::CondVar requestsDone;
+
+    /**
+     * Indicate if the queue is enabled or not.
+     */
+    volatile bool enabled;
+
+    /**
+     * The vector of the queued requests.
+     */
+    requests_t requests;
+
+public:
+    /**
+     * Construct the queue. It creates the flight loop, so it should
+     * be called from a plugin callback.
+     */
+    RequestQueue();
+
+    /**
+     * Execute the given request. It will be enqueued, and then this
+     * function will wait until the request is executed or the request
+     * queue is disabled.
+     *
+     * If the queue is already disabled when calling this function, it
+     * returns immediately with false.
+     *
+     * @return if the request was executed
+     */
+    bool execute(Request* request);
+
+    /**
+     * Disable the queue. It sets the flag indicating that the queue
+     * is disabled, and wakes up all waiters waiting on the
+     * conditional variable. It should be called from a plugin
+     * callback, as it also destroys the flight loop.
+     */
+    void disable();
+
+private:
+    /**
+     * Run the queue.
+     *
+     * It locks the mutex, swaps the vector of requests with an empty
+     * one, unlocks the mutex and runs the requests one by one. When
+     * all requests are executed, it wakes up all waiters waiting on
+     * the conditional variable.
+     *
+     * It is called from the flight loop function.
+     */
+    void run();
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplra */
+
+//------------------------------------------------------------------------------
+#endif // XPLRA_REQUESTQUEUE_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplra/ServerThread.cc
===================================================================
--- src/xplra/ServerThread.cc	(revision 2)
+++ src/xplra/ServerThread.cc	(revision 2)
@@ -0,0 +1,101 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of XPLRA, a remote-access plugin for 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 "ServerThread.h"
+
+//------------------------------------------------------------------------------
+
+using xplra::ServerThread;
+
+using xplcommon::LocalAcceptor;
+using xplcommon::Mutex;
+
+//------------------------------------------------------------------------------
+
+Mutex ServerThread::instancesMutex;
+
+ServerThread::instances_t ServerThread::instances;
+
+//------------------------------------------------------------------------------
+
+void ServerThread::quitAll()
+{
+    instancesMutex.lock();
+    for(instances_t::iterator i = instances.begin(); i!=instances.end(); ++i) {
+        (*i)->quit();
+    }
+    instancesMutex.unlock();
+}
+
+//------------------------------------------------------------------------------
+
+ServerThread::ServerThread(LocalAcceptor& acceptor) :
+    Thread(true),
+    bufferedStream(acceptor.getSocket(&waiter)),
+    stream(*bufferedStream)
+{
+    instancesMutex.lock();
+    instances.insert(this);
+    instancesMutex.unlock();
+}
+
+//------------------------------------------------------------------------------
+
+ServerThread::~ServerThread()
+{
+    delete bufferedStream;
+
+    instancesMutex.lock();
+    instances.erase(this);
+    instancesMutex.unlock();
+}
+
+//------------------------------------------------------------------------------
+
+void ServerThread::quit()
+{
+    stream.interrupt();
+}
+
+//------------------------------------------------------------------------------
+
+void ServerThread::run()
+{
+    stream.write("Hello, world!", 13);
+    stream.flush();
+}
+
+//------------------------------------------------------------------------------
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
Index: src/xplra/ServerThread.h
===================================================================
--- src/xplra/ServerThread.h	(revision 2)
+++ src/xplra/ServerThread.h	(revision 2)
@@ -0,0 +1,127 @@
+// Copyright (c) 2013 by István Váradi
+
+// This file is part of XPLRA, a remote-access plugin for 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 XPLRA_SERVERTHREAD_H
+#define XPLRA_SERVERTHREAD_H
+//------------------------------------------------------------------------------
+
+#include <xplcommon/Thread.h>
+
+#include <xplcommon/Mutex.h>
+
+#include <xplcommon/Waiter.h>
+#include <xplcommon/BufferedStream.h>
+#include <xplcommon/BlockingStream.h>
+#include <xplcommon/LocalAcceptor.h>
+
+#include <set>
+
+//------------------------------------------------------------------------------
+
+namespace xplra {
+
+//------------------------------------------------------------------------------
+
+/**
+ * A thread serving a client.
+ */
+class ServerThread : public xplcommon::Thread
+{
+private:
+    /**
+     * Type for the set of server thread instances.
+     */
+    typedef std::set<ServerThread*> instances_t;
+
+    /**
+     * A mutex to protect the collection of server threads.
+     */
+    static xplcommon::Mutex instancesMutex;
+
+    /**
+     * The instances of this class.
+     */
+    static instances_t instances;
+
+public:
+    /**
+     * Call quit() an all threads.
+     */
+    static void quitAll();
+
+private:
+    /**
+     * Our waiter.
+     */
+    xplcommon::Waiter waiter;
+
+    /**
+     * The buffered stream to use for communication at the low-level.
+     */
+    xplcommon::BufferedStream* bufferedStream;
+
+    /**
+     * The blocking stream being used for communication.
+     */
+    xplcommon::BlockingStream stream;
+
+public:
+    /**
+     * Construct the thread by using a LocalSocket returned by the
+     * given acceptor.
+     */
+    ServerThread(xplcommon::LocalAcceptor& acceptor);
+
+    /**
+     * Destroy the thread.
+     */
+    virtual ~ServerThread();
+
+    /**
+     * Quit the thread. It interrupts the blocking stream.
+     */
+    void quit();
+
+    /**
+     * Perform the thread's operation.
+     */
+    virtual void run();
+};
+
+//------------------------------------------------------------------------------
+
+} /* namespace xplra */
+
+//------------------------------------------------------------------------------
+#endif // XPLRA_SERVERTHREAD_H
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 4
+// indent-tabs-mode: nil
+// End:
