From c82c636d8c9ac24c1e73740c35b3a93525783a3d Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Wed, 8 Feb 2012 10:02:46 +0000 Subject: cSocketThreads plugged in for cClientHandle reading. Sending still kept the old way. Please help me test this commit thoroughly, this is a change that can break on subtleties. git-svn-id: http://mc-server.googlecode.com/svn/trunk@244 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cSocketThreads.h | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'source/cSocketThreads.h') diff --git a/source/cSocketThreads.h b/source/cSocketThreads.h index b43d693ba..cbf73a27e 100644 --- a/source/cSocketThreads.h +++ b/source/cSocketThreads.h @@ -10,7 +10,7 @@ /// How many clients should one thread handle? (must be less than FD_SETSIZE - 1 for your platform) -#define MAX_SLOTS 1 +#define MAX_SLOTS 63 @@ -65,17 +65,17 @@ public: cSocketThreads(void); ~cSocketThreads(); - /// Add a (socket, client) pair for processing, data from a_Socket is to be sent to a_Client - void AddClient(cSocket * a_Socket, cCallback * a_Client); + /// Add a (socket, client) pair for processing, data from a_Socket is to be sent to a_Client; returns true if successful + bool AddClient(cSocket * a_Socket, cCallback * a_Client); /// Remove the socket (and associated client) from processing - void RemoveClient(cSocket * a_Socket); + void RemoveClient(const cSocket * a_Socket); /// Remove the associated socket and the client from processing - void RemoveClient(cCallback * a_Client); + void RemoveClient(const cCallback * a_Client); /// Notify the thread responsible for a_Client that the client has something to write - void NotifyWrite(cCallback * a_Client); + void NotifyWrite(const cCallback * a_Client); private: @@ -92,15 +92,17 @@ private: bool HasEmptySlot(void) const {return m_NumSlots < MAX_SLOTS; } bool IsEmpty (void) const {return m_NumSlots == 0; } - void AddClient (cSocket * a_Socket, cCallback * a_Client); - bool RemoveClient(cCallback * a_Client); // Returns true if removed, false if not found - bool RemoveSocket(cSocket * a_Socket); // Returns true if removed, false if not found - bool HasClient (cCallback * a_Client) const; - bool HasSocket (cSocket * a_Socket) const; - bool NotifyWrite (cCallback * a_Client); // Returns true if client handled by this thread + void AddClient (cSocket * a_Socket, cCallback * a_Client); + bool RemoveClient(const cCallback * a_Client); // Returns true if removed, false if not found + bool RemoveSocket(const cSocket * a_Socket); // Returns true if removed, false if not found + bool HasClient (const cCallback * a_Client) const; + bool HasSocket (const cSocket * a_Socket) const; + bool NotifyWrite (const cCallback * a_Client); // Returns true if client handled by this thread bool Start(void); // Hide the cIsThread's Start method, we need to provide our own startup to create the control socket + bool IsValid(void) const {return m_ControlSocket2.IsValid(); } // If the Control socket dies, the thread is not valid anymore + private: cSocketThreads * m_Parent; @@ -127,6 +129,7 @@ private: void PrepareSet (fd_set * a_Set, cSocket::xSocket & a_Highest); // Puts all sockets into the set, along with m_ControlSocket1 void ReadFromSockets(fd_set * a_Read); // Reads from sockets indicated in a_Read void WriteToSockets (fd_set * a_Write); // Writes to sockets indicated in a_Write + void RemoveClosedSockets(void); // Removes sockets that have closed from m_Slots[] } ; typedef std::list cSocketThreadList; -- cgit v1.2.3