diff options
author | rubidium <rubidium@openttd.org> | 2009-04-10 20:18:48 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-04-10 20:18:48 +0000 |
commit | 2663ad302f366ecd2498a43470855c4cf73839d6 (patch) | |
tree | a6e4b4d85cbe3a6448e01b6ffc8ba0e9efe25b56 | |
parent | 238742ee036f483f12a84ba7033fc8ef67506201 (diff) | |
download | openttd-2663ad302f366ecd2498a43470855c4cf73839d6.tar.xz |
(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.
-rw-r--r-- | src/network/network.cpp | 13 | ||||
-rw-r--r-- | src/network/network_func.h | 2 | ||||
-rw-r--r-- | src/network/network_udp.cpp | 11 | ||||
-rw-r--r-- | src/network/network_udp.h | 2 |
4 files changed, 17 insertions, 11 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp index 3965d8ef7..d2d276495 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -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"); diff --git a/src/network/network_func.h b/src/network/network_func.h index 88a4329a4..37e19b4d6 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -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(); diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp index 74c732710..efb8883be 100644 --- a/src/network/network_udp.cpp +++ b/src/network/network_udp.cpp @@ -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); } } diff --git a/src/network/network_udp.h b/src/network/network_udp.h index 57a29a49c..ac1a131b7 100644 --- a/src/network/network_udp.h +++ b/src/network/network_udp.h @@ -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 */ |