summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-02-08 21:47:10 +0000
committerrubidium <rubidium@openttd.org>2011-02-08 21:47:10 +0000
commit05a846a574e277adf8beb2ab5e021fe49f1f7fc9 (patch)
tree3866b175dc2151ca2cf5e65f22e1ff87c14646c5 /src/network
parent537bd8a429a930a66c171ba6e6760352a99c2915 (diff)
downloadopenttd-05a846a574e277adf8beb2ab5e021fe49f1f7fc9.tar.xz
(svn r22032) -Codechange: add some asserts to verify we don't allocate too many NetworkClientSockets/Infos
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network.cpp2
-rw-r--r--src/network/network_server.cpp15
2 files changed, 16 insertions, 1 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 0902fcdb0..04268dbf6 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -682,6 +682,8 @@ static void NetworkInitGameInfo()
/* The server is a client too */
_network_game_info.clients_on = _network_dedicated ? 0 : 1;
+ /* There should be always space for the server. */
+ assert(NetworkClientInfo::CanAllocateItem());
NetworkClientInfo *ci = new NetworkClientInfo(CLIENT_ID_SERVER);
ci->client_playas = _network_dedicated ? COMPANY_SPECTATOR : _local_company;
/* Give the server a valid IP; banning it is pointless anyways */
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index d79c5b566..be27d75a6 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -155,6 +155,13 @@ ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(SOCKET s) : Netwo
this->status = STATUS_INACTIVE;
this->client_id = _network_client_id++;
this->receive_limit = _settings_client.network.bytes_per_frame_burst;
+
+ /* The Socket and Info pools need to be the same in size. After all,
+ * each Socket will be associated with at most one Info object. As
+ * such if the Socket was allocated the Info object can as well. */
+ assert_compile(NetworkClientSocketPool::MAX_SIZE == NetworkClientInfoPool::MAX_SIZE);
+ assert(NetworkClientInfo::CanAllocateItem());
+
NetworkClientInfo *ci = new NetworkClientInfo(this->client_id);
this->SetInfo(ci);
ci->client_playas = COMPANY_INACTIVE_CLIENT;
@@ -250,7 +257,13 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta
/* static */ bool ServerNetworkGameSocketHandler::AllowConnection()
{
extern byte _network_clients_connected;
- return _network_clients_connected < MAX_CLIENTS && _network_game_info.clients_on < _settings_client.network.max_clients;
+ bool accept = _network_clients_connected < MAX_CLIENTS && _network_game_info.clients_on < _settings_client.network.max_clients;
+
+ /* We can't go over the MAX_CLIENTS limit here. However, the
+ * pool must have place for all clients and ourself. */
+ assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENTS + 1);
+ assert(ServerNetworkGameSocketHandler::CanAllocateItem());
+ return accept;
}
/** Send the packets for the server sockets. */