summaryrefslogtreecommitdiff
path: root/src/network/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/core')
-rw-r--r--src/network/core/tcp_game.cpp6
-rw-r--r--src/network/core/tcp_game.h18
2 files changed, 17 insertions, 7 deletions
diff --git a/src/network/core/tcp_game.cpp b/src/network/core/tcp_game.cpp
index 8044ef138..66a1b6f81 100644
--- a/src/network/core/tcp_game.cpp
+++ b/src/network/core/tcp_game.cpp
@@ -36,12 +36,6 @@ NetworkClientSocket::NetworkClientSocket(ClientID client_id)
NetworkClientSocket::~NetworkClientSocket()
{
- while (this->command_queue != NULL) {
- CommandPacket *p = this->command_queue->next;
- free(this->command_queue);
- this->command_queue = p;
- }
-
if (_redirect_console_to_client == this->client_id) _redirect_console_to_client = INVALID_CLIENT_ID;
this->client_id = INVALID_CLIENT_ID;
this->status = STATUS_INACTIVE;
diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h
index 70a261d08..d6952d1bf 100644
--- a/src/network/core/tcp_game.h
+++ b/src/network/core/tcp_game.h
@@ -74,6 +74,22 @@ enum TCPPacketType {
/** Packet that wraps a command */
struct CommandPacket;
+/** A queue of CommandPackets. */
+class CommandQueue {
+ CommandPacket *first; ///< The first packet in the queue.
+ CommandPacket *last; ///< The last packet in the queue; only valid when first != NULL.
+
+public:
+ /** Initialise the command queue. */
+ CommandQueue() : first(NULL), last(NULL) {}
+ /** Clear the command queue. */
+ ~CommandQueue() { this->Free(); }
+ void Append(CommandPacket *p);
+ CommandPacket *Pop();
+ CommandPacket *Peek();
+ void Free();
+};
+
/** Status of a client */
enum ClientStatus {
STATUS_INACTIVE, ///< The client is not connected nor active
@@ -106,7 +122,7 @@ public:
ClientStatus status; ///< Status of this client
- CommandPacket *command_queue; ///< The command-queue awaiting delivery
+ CommandQueue command_queue; ///< The command-queue awaiting delivery
NetworkRecvStatus CloseConnection(bool error = true);