(svn r16022) -Fix (r15159): sometimes the unregister "query" thread could be delayed so much that the network stuff was already closed and the packet would never reach the master server causing the server to appear online longer than necessary.

This commit is contained in:
rubidium 2009-04-10 20:18:48 +00:00
parent 238742ee03
commit 2663ad302f
4 changed files with 17 additions and 11 deletions

View File

@ -586,7 +586,7 @@ static void NetworkClose()
closesocket(s->second);
}
_listensockets.Clear();
DEBUG(net, 1, "Closed listener");
DEBUG(net, 1, "[tcp] closed listeners");
}
TCPConnecter::KillAll();
@ -813,8 +813,11 @@ void NetworkReboot()
NetworkClose();
}
/* We want to disconnect from the host/clients */
void NetworkDisconnect()
/**
* We want to disconnect from the host/clients.
* @param blocking whether to wait till everything has been closed
*/
void NetworkDisconnect(bool blocking)
{
if (_network_server) {
NetworkClientSocket *cs;
@ -824,7 +827,7 @@ void NetworkDisconnect()
}
}
if (_settings_client.network.server_advertise) NetworkUDPRemoveAdvertise();
if (_settings_client.network.server_advertise) NetworkUDPRemoveAdvertise(blocking);
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0);
@ -1104,7 +1107,7 @@ void NetworkStartUp()
/** This shuts the network down */
void NetworkShutDown()
{
NetworkDisconnect();
NetworkDisconnect(true);
NetworkUDPClose();
DEBUG(net, 3, "[core] shutting down network");

View File

@ -30,7 +30,7 @@ void NetworkUpdateClientName();
bool NetworkCompanyHasClients(CompanyID company);
bool NetworkChangeCompanyPassword(byte argc, char *argv[]);
void NetworkReboot();
void NetworkDisconnect();
void NetworkDisconnect(bool blocking = false);
void NetworkGameLoop();
void NetworkUDPGameLoop();
void NetworkUDPCloseAll();

View File

@ -58,7 +58,7 @@ DEF_UDP_RECEIVE_COMMAND(Master, PACKET_UDP_MASTER_ACK_REGISTER)
DEBUG(net, 2, "[udp] advertising on master server successful");
/* We are advertised, but we don't want to! */
if (!_settings_client.network.server_advertise) NetworkUDPRemoveAdvertise();
if (!_settings_client.network.server_advertise) NetworkUDPRemoveAdvertise(false);
}
DEF_UDP_RECEIVE_COMMAND(Master, PACKET_UDP_MASTER_SESSION_KEY)
@ -474,13 +474,16 @@ void NetworkUDPRemoveAdvertiseThread(void *pntr)
_network_udp_mutex->EndCritical();
}
/* Remove our advertise from the master-server */
void NetworkUDPRemoveAdvertise()
/**
* Remove our advertise from the master-server.
* @param blocking whether to wait until the removal has finished.
*/
void NetworkUDPRemoveAdvertise(bool blocking)
{
/* Check if we are advertising */
if (!_networking || !_network_server || !_network_udp_server) return;
if (!ThreadObject::New(NetworkUDPRemoveAdvertiseThread, NULL)) {
if (blocking || !ThreadObject::New(NetworkUDPRemoveAdvertiseThread, NULL)) {
NetworkUDPRemoveAdvertiseThread(NULL);
}
}

View File

@ -12,7 +12,7 @@ void NetworkUDPSearchGame();
void NetworkUDPQueryMasterServer();
void NetworkUDPQueryServer(NetworkAddress address, bool manually = false);
void NetworkUDPAdvertise();
void NetworkUDPRemoveAdvertise();
void NetworkUDPRemoveAdvertise(bool blocking);
void NetworkUDPClose();
#endif /* ENABLE_NETWORK */