diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-26 00:48:28 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-26 00:48:28 +0100 |
commit | a14e015354611a50920a0861f80c9691ab8fa633 (patch) | |
tree | 49e573603f5cff7dc551fa79d08e1d801ef3d8ca /source/cSocketThreads.h | |
parent | Made the viewdistance settable by users and default in settings.ini. The default is 9. (diff) | |
download | cuberite-a14e015354611a50920a0861f80c9691ab8fa633.tar cuberite-a14e015354611a50920a0861f80c9691ab8fa633.tar.gz cuberite-a14e015354611a50920a0861f80c9691ab8fa633.tar.bz2 cuberite-a14e015354611a50920a0861f80c9691ab8fa633.tar.lz cuberite-a14e015354611a50920a0861f80c9691ab8fa633.tar.xz cuberite-a14e015354611a50920a0861f80c9691ab8fa633.tar.zst cuberite-a14e015354611a50920a0861f80c9691ab8fa633.zip |
Diffstat (limited to 'source/cSocketThreads.h')
-rw-r--r-- | source/cSocketThreads.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/source/cSocketThreads.h b/source/cSocketThreads.h index a32808aeb..a8174a115 100644 --- a/source/cSocketThreads.h +++ b/source/cSocketThreads.h @@ -5,6 +5,16 @@ // This object takes care of network communication, groups sockets into threads and uses as little threads as possible for full read / write support
// For more detail, see http://forum.mc-server.org/showthread.php?tid=327
+/*
+Additional details:
+When a client is terminating a connection:
+- they call the StopReading() method to disable callbacks for the incoming data
+- they call the Write() method to queue any outstanding outgoing data
+- they call the QueueClose() method to queue the socket to close after outgoing data has been sent.
+When a socket slot is marked as having no callback, it is kept alive until its outgoing data queue is empty and its m_ShouldClose flag is set.
+This means that the socket can be written to several times before finally closing it via QueueClose()
+*/
+
@@ -76,6 +86,15 @@ public: /// Notify the thread responsible for a_Client that the client has something to write
void NotifyWrite(const cCallback * a_Client);
+
+ /// Puts a_Data into outgoing data queue for a_Socket
+ void Write(const cSocket * a_Socket, const AString & a_Data);
+
+ /// Stops reading from the socket - when this call returns, no more calls to the callbacks are made
+ void StopReading(const cCallback * a_Client);
+
+ /// Queues the socket for closing, as soon as its outgoing data is sent
+ void QueueClose(const cSocket * a_Socket);
private:
@@ -99,6 +118,9 @@ private: 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 Write (const cSocket * a_Socket, const AString & a_Data); // Returns true if socket handled by this thread
+ bool StopReading (const cCallback * a_Client); // Returns true if client handled by this thread
+ bool QueueClose (const cSocket * a_Socket); // Returns true if socket 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
@@ -119,6 +141,7 @@ private: cSocket * m_Socket;
cCallback * m_Client;
AString m_Outgoing; // If sending writes only partial data, the rest is stored here for another send
+ bool m_ShouldClose; // If true, the socket is to be closed after sending all outgoing data
} ;
sSlot m_Slots[MAX_SLOTS];
int m_NumSlots; // Number of slots actually used
|