fixes port-in-use deadlock
This commit is contained in:
@@ -44,7 +44,7 @@ namespace OpenRA.Server
|
|||||||
const int DownloadChunkInterval = 20000;
|
const int DownloadChunkInterval = 20000;
|
||||||
const int DownloadChunkSize = 16384;
|
const int DownloadChunkSize = 16384;
|
||||||
|
|
||||||
public static int ServerMain(string[] mods, AutoResetEvent e)
|
public static void ServerMain(string[] mods)
|
||||||
{
|
{
|
||||||
initialMods = mods;
|
initialMods = mods;
|
||||||
|
|
||||||
@@ -58,16 +58,14 @@ namespace OpenRA.Server
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
listener.Start();
|
listener.Start();
|
||||||
Console.WriteLine("Server started.");
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Server failed to start.");
|
throw new InvalidOperationException( "Unable to start server: port is already in use" );
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
e.Set(); // we're done starting up
|
new Thread( _ =>
|
||||||
|
{
|
||||||
for( ; ; )
|
for( ; ; )
|
||||||
{
|
{
|
||||||
var checkRead = new ArrayList();
|
var checkRead = new ArrayList();
|
||||||
@@ -86,7 +84,7 @@ namespace OpenRA.Server
|
|||||||
foreach( var c in conns.Where( a => a.Stream != null ).ToArray() )
|
foreach( var c in conns.Where( a => a.Stream != null ).ToArray() )
|
||||||
SendNextChunk( c );
|
SendNextChunk( c );
|
||||||
}
|
}
|
||||||
|
} ) { IsBackground = true }.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ChooseFreePlayerIndex()
|
static int ChooseFreePlayerIndex()
|
||||||
@@ -550,11 +548,7 @@ namespace OpenRA.Server
|
|||||||
|
|
||||||
public static void Start( string[] mods )
|
public static void Start( string[] mods )
|
||||||
{
|
{
|
||||||
var e = new AutoResetEvent(false);
|
Server.ServerMain( mods );
|
||||||
t = new Thread(() => Server.ServerMain(mods, e)) { IsBackground = true };
|
|
||||||
|
|
||||||
t.Start();
|
|
||||||
e.WaitOne(); // when the event is signaled, the server is finished initializing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Stop()
|
public static void Stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user