summaryrefslogtreecommitdiffstats
path: root/source/ListenThread.h
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-03-04 22:13:08 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-03-04 22:13:08 +0100
commit28d8d8419a5b900e9d20ce91dc63e28349b6470a (patch)
treebf5b7bafa902a138339c78877ecec376c055b727 /source/ListenThread.h
parentRemoved the unused cHeartbeat object (diff)
downloadcuberite-28d8d8419a5b900e9d20ce91dc63e28349b6470a.tar
cuberite-28d8d8419a5b900e9d20ce91dc63e28349b6470a.tar.gz
cuberite-28d8d8419a5b900e9d20ce91dc63e28349b6470a.tar.bz2
cuberite-28d8d8419a5b900e9d20ce91dc63e28349b6470a.tar.lz
cuberite-28d8d8419a5b900e9d20ce91dc63e28349b6470a.tar.xz
cuberite-28d8d8419a5b900e9d20ce91dc63e28349b6470a.tar.zst
cuberite-28d8d8419a5b900e9d20ce91dc63e28349b6470a.zip
Diffstat (limited to '')
-rw-r--r--source/ListenThread.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/source/ListenThread.h b/source/ListenThread.h
new file mode 100644
index 000000000..90523ea4f
--- /dev/null
+++ b/source/ListenThread.h
@@ -0,0 +1,75 @@
+
+// ListenThread.h
+
+// Declares the cListenThread class representing the thread that listens for client connections
+
+
+
+
+
+#pragma once
+
+#include "OSSupport/IsThread.h"
+#include "OSSupport/Socket.h"
+
+
+
+
+
+// fwd:
+class cServer;
+
+
+
+
+
+class cListenThread :
+ public cIsThread
+{
+ typedef cIsThread super;
+
+public:
+ /// Used as the callback for connection events
+ class cCallback
+ {
+ public:
+ /// This callback is called whenever a socket connection is accepted
+ virtual void OnConnectionAccepted(cSocket & a_Socket) = 0;
+ } ;
+
+ cListenThread(cCallback & a_Callback);
+ ~cListenThread();
+
+ /// Creates all the sockets, returns trus if successful, false if not.
+ bool Initialize(const AString & a_PortsString);
+
+ bool Start(void);
+
+ void Stop(void);
+
+ /// Call before Initialize() to set the "reuse" flag on the sockets
+ void SetReuseAddr(bool a_Reuse = true);
+
+protected:
+ typedef std::vector<cSocket> cSockets;
+
+ /// The callback which to notify of incoming connections
+ cCallback & m_Callback;
+
+ /// Sockets that are being monitored
+ cSockets m_Sockets;
+
+ bool m_ShouldReuseAddr;
+
+ /** Fills in m_Sockets with individual sockets, each for one port specified in a_PortsString.
+ Returns true if successful and at least one socket has been created
+ */
+ bool CreateSockets(const AString & a_PortsString);
+
+ // cIsThread override:
+ virtual void Execute(void) override;
+} ;
+
+
+
+