summaryrefslogtreecommitdiffstats
path: root/source/cServer.h
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-26 01:36:51 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-26 01:36:51 +0100
commit0e33c919dd5c954e0e9d266924c1650237bb95a1 (patch)
tree32f4f3c136da43a9edaaa4921979ac4c0518743c /source/cServer.h
parentExtended SocketThreads for writing support (unusable in cClientHandle due to too many deadlock possibilities) (diff)
downloadcuberite-0e33c919dd5c954e0e9d266924c1650237bb95a1.tar
cuberite-0e33c919dd5c954e0e9d266924c1650237bb95a1.tar.gz
cuberite-0e33c919dd5c954e0e9d266924c1650237bb95a1.tar.bz2
cuberite-0e33c919dd5c954e0e9d266924c1650237bb95a1.tar.lz
cuberite-0e33c919dd5c954e0e9d266924c1650237bb95a1.tar.xz
cuberite-0e33c919dd5c954e0e9d266924c1650237bb95a1.tar.zst
cuberite-0e33c919dd5c954e0e9d266924c1650237bb95a1.zip
Diffstat (limited to '')
-rw-r--r--source/cServer.h44
1 files changed, 41 insertions, 3 deletions
diff --git a/source/cServer.h b/source/cServer.h
index 3e7fbf094..200f2bb1f 100644
--- a/source/cServer.h
+++ b/source/cServer.h
@@ -21,6 +21,8 @@ class cPlayer;
class cClientHandle;
class cPacket;
+typedef std::list<cClientHandle *> cClientHandleList;
+
@@ -58,16 +60,48 @@ public: //tolua_export
void ClientDestroying(const cClientHandle * a_Client); // Called by cClientHandle::Destroy(); removes the client from m_SocketThreads
+ void NotifyClientWrite(const cClientHandle * a_Client); // Notifies m_SocketThreads that client has something to be written
+
+ void WriteToClient(const cSocket * a_Socket, const AString & a_Data); // Queues outgoing data for the socket through m_SocketThreads
+
+ void QueueClientClose(const cSocket * a_Socket); // Queues the socket to close when all its outgoing data is sent
+
private:
friend class cRoot; // so cRoot can create and destroy cServer
- cServer();
- ~cServer();
-
+ /// When NotifyClientWrite() is called, it is queued for this thread to process (to avoid deadlocks between cSocketThreads, cClientHandle and cChunkMap)
+ class cNotifyWriteThread :
+ public cIsThread
+ {
+ typedef cIsThread super;
+
+ cEvent m_Event; // Set when m_Clients gets appended
+ cServer * m_Server;
+
+ cCriticalSection m_CS;
+ cClientHandleList m_Clients;
+
+ virtual void Execute(void);
+
+ public:
+
+ cNotifyWriteThread(void);
+ ~cNotifyWriteThread();
+
+ bool Start(cServer * a_Server);
+
+ void NotifyClientWrite(const cClientHandle * a_Client);
+ } ;
+
struct sServerState;
sServerState* m_pState;
+ cNotifyWriteThread m_NotifyWriteThread;
+
+ cCriticalSection m_CSClients; // Locks client list
+ cClientHandleList m_Clients; // Clients that are connected to the server
+
cSocketThreads m_SocketThreads;
int m_ClientViewDistance; // The default view distance for clients; settable in Settings.ini
@@ -80,6 +114,10 @@ private:
int m_iServerPort;
bool m_bRestarting;
+
+ cServer();
+ ~cServer();
+
}; //tolua_export