diff options
author | rubidium <rubidium@openttd.org> | 2010-08-15 23:44:45 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-08-15 23:44:45 +0000 |
commit | 1c3d42598e1de68e109ee27dd289885aabe9878b (patch) | |
tree | ace3c990a6bb5df5dc8585af9caa895be3c4b4a1 /src/network/core/tcp_game.h | |
parent | 12b882227717811b047d4ae84d95444b167d7226 (diff) | |
download | openttd-1c3d42598e1de68e109ee27dd289885aabe9878b.tar.xz |
(svn r20510) -Codechange: unify packet queue handling and make insertion O(1) instead of O(n)
Diffstat (limited to 'src/network/core/tcp_game.h')
-rw-r--r-- | src/network/core/tcp_game.h | 18 |
1 files changed, 17 insertions, 1 deletions
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); |