summaryrefslogtreecommitdiff
path: root/src/network/core/tcp.h
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-12-23 20:52:27 +0000
committerrubidium <rubidium@openttd.org>2008-12-23 20:52:27 +0000
commitafddfcb2b1a37358459158ce83a64535f13cd05e (patch)
tree5fc12b987e4ccf94d7c727fd7c3eccc1826b870a /src/network/core/tcp.h
parent94dd23aaf86cb1c22ce78d8555261d045de0ee60 (diff)
downloadopenttd-afddfcb2b1a37358459158ce83a64535f13cd05e.tar.xz
(svn r14730) -Codechange: remove the need for networkclientsockets and networkclientinfo structs to be in a contiguous piece of memory and put them in a pool.
-Note: 255 should really be enough for now... making it any more means network protocol bumps.
Diffstat (limited to 'src/network/core/tcp.h')
-rw-r--r--src/network/core/tcp.h30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h
index aa5bb7c4a..06d382f6c 100644
--- a/src/network/core/tcp.h
+++ b/src/network/core/tcp.h
@@ -84,12 +84,17 @@ enum ClientStatus {
STATUS_ACTIVE, ///< The client is active within in the game
};
+
+class NetworkClientSocket;
+DECLARE_OLD_POOL(NetworkClientSocket, NetworkClientSocket, NCI_BITS_PER_POOL_BLOCK, MAX_CLIENT_SLOTS >> NCI_BITS_PER_POOL_BLOCK);
+
/** Base socket handler for all TCP sockets */
-class NetworkClientSocket : public NetworkSocketHandler {
+class NetworkClientSocket : public PoolItem<NetworkClientSocket, ClientIndex, &_NetworkClientSocket_pool>, public NetworkSocketHandler {
/* TODO: rewrite into a proper class */
private:
Packet *packet_queue; ///< Packets that are awaiting delivery
Packet *packet_recv; ///< Partially received packet
+ NetworkClientInfo *info; ///< Client info related to this socket
public:
ClientID client_id; ///< Client identifier
uint32 last_frame; ///< Last frame we have executed
@@ -102,8 +107,6 @@ public:
CommandPacket *command_queue; ///< The command-queue awaiting delivery
NetworkRecvStatus CloseConnection();
- void Initialize();
- void Destroy();
void Send_Packet(Packet *packet);
bool Send_Packets();
@@ -111,27 +114,24 @@ public:
Packet *Recv_Packet(NetworkRecvStatus *status);
+ NetworkClientSocket(ClientID client_id = INVALID_CLIENT_ID);
+ ~NetworkClientSocket();
+
inline bool IsValid() const { return this->IsConnected(); }
- inline NetworkClientInfo *GetInfo() const
- {
- extern NetworkClientSocket _clients[MAX_CLIENTS];
- return GetNetworkClientInfo(this - _clients);
- }
+ inline void SetInfo(NetworkClientInfo *info) { assert(info != NULL && this->info == NULL); this->info = info; }
+ inline NetworkClientInfo *GetInfo() const { return this->info; }
};
-// Here we keep track of the clients
-// (and the client uses [0] for his own communication)
-extern NetworkClientSocket _clients[MAX_CLIENTS];
-#define GetNetworkClientSocket(i) (&_clients[i])
-
static inline bool IsValidNetworkClientSocketIndex(ClientIndex index)
{
- return (uint)index < MAX_CLIENTS && GetNetworkClientSocket(index)->IsValid();
+ return (uint)index < GetNetworkClientSocketPoolSize() && GetNetworkClientSocket(index)->IsValid();
}
-#define FOR_ALL_CLIENT_SOCKETS_FROM(d, start) for (d = GetNetworkClientSocket(start); d != GetNetworkClientSocket(MAX_CLIENTS); d++) if (d->IsValid())
+#define FOR_ALL_CLIENT_SOCKETS_FROM(d, start) for (d = (start < GetNetworkClientSocketPoolSize() ? GetNetworkClientSocket(start) : NULL); d != NULL; d = (d->index + 1U < GetNetworkClientSocketPoolSize()) ? GetNetworkClientSocket(d->index + 1U) : NULL) if (d->IsValid())
#define FOR_ALL_CLIENT_SOCKETS(d) FOR_ALL_CLIENT_SOCKETS_FROM(d, 0)
+typedef NetworkClientSocket NetworkTCPSocketHandler;
+
#endif /* ENABLE_NETWORK */
#endif /* NETWORK_CORE_TCP_H */