(svn r22032) -Codechange: add some asserts to verify we don't allocate too many NetworkClientSockets/Infos

This commit is contained in:
rubidium 2011-02-08 21:47:10 +00:00
parent 537bd8a429
commit 05a846a574
2 changed files with 16 additions and 1 deletions

View File

@ -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 */

View File

@ -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. */