threadsafe

This commit is contained in:
alzeih
2010-07-23 19:03:33 +12:00
committed by Chris Forbes
parent 282d26b844
commit 984e081f3b
5 changed files with 26 additions and 17 deletions

View File

@@ -619,6 +619,7 @@ namespace OpenRA
public static void Disconnect()
{
orderManager.Dispose();
var shellmap = Manifest.ShellmapUid;
LobbyInfo = new Session();
LobbyInfo.GlobalSettings.Mods = Settings.InitialMods;

View File

@@ -74,15 +74,16 @@ namespace OpenRA.Network
}
}
class NetworkConnection : EchoConnection
class NetworkConnection : EchoConnection, IDisposable
{
TcpClient socket;
int clientId;
ConnectionState connectionState = ConnectionState.Connecting;
Thread t;
public NetworkConnection( string host, int port )
{
new Thread( _ =>
t = new Thread( _ =>
{
try
{
@@ -115,7 +116,8 @@ namespace OpenRA.Network
connectionState = ConnectionState.NotConnected;
}
}
) { IsBackground = true }.Start();
) { IsBackground = true };
t.Start();
}
public override int LocalClientId { get { return clientId; } }
@@ -136,6 +138,18 @@ namespace OpenRA.Network
}
catch (SocketException) { /* drop this on the floor; we'll pick up the disconnect from the reader thread */ }
}
bool disposed = false;
public void Dispose ()
{
if (disposed) return;
disposed = true;
GC.SuppressFinalize( this );
socket.Close();
t.Abort();
}
~NetworkConnection() { Dispose(); }
}
class ReplayConnection : IConnection

View File

@@ -90,6 +90,13 @@ namespace OpenRA.Server
if (Environment.TickCount - lastPing > MasterPingInterval * 1000)
PingMasterServer();
if (conns.Count() == 0)
{
listener.Stop();
GameStarted = false;
break;
}
}
} ) { IsBackground = true }.Start();
}
@@ -424,15 +431,6 @@ namespace OpenRA.Server
if (conns.Count != 0)
SyncLobbyInfo();
}
public static void CloseServer()
{
while (conns.Count() != 0)
DropClient(conns.ElementAt(conns.Count() - 1), null);
if (listener != null)
listener.Stop();
GameStarted = false;
}
static void SyncLobbyInfo()
{

View File

@@ -29,9 +29,7 @@ namespace OpenRA.Widgets.Delegates
};
optionsBG.GetWidget("BUTTON_DISCONNECT").OnMouseUp = mi => {
optionsBG.Visible = false;
if (Game.IsHost)
Server.Server.CloseServer();
optionsBG.Visible = false;
Game.Disconnect();
return true;
};

View File

@@ -80,8 +80,6 @@ namespace OpenRA.Widgets.Delegates
var disconnectButton = lobby.GetWidget("DISCONNECT_BUTTON");
disconnectButton.OnMouseUp = mi =>
{
if (Game.IsHost)
Server.Server.CloseServer();
Game.Disconnect();
return true;
};