Skip to content
Permalink
Browse files

[skip ci] GSDumpGUI: Fixes multiinstance crashes. (#2925)

- automatically find the next free TCP port yielded by OS
- transfering currently used instance-fixed port to launched clients
- connect each client via given port

See #1637
  • Loading branch information...
willkuer authored and lightningterror committed Apr 14, 2019
1 parent 075a9f3 commit 48b2383096bf5dfa39ce4e7bf904a2a849165813
@@ -52,16 +52,17 @@ static class Program
[STAThread]
static void Main(String[] args)
{
if (args.Length == 4)
if (args.Length == 5)
{
// do this first, else racy mess ;)
wrap = new GSDXWrapper();
var port = Convert.ToInt32(args[4]);

try
{
Client = new TCPLibrary.MessageBased.Core.BaseMessageClient();
Client.OnMessageReceived += new TCPLibrary.MessageBased.Core.BaseMessageClient.MessageReceivedHandler(Client_OnMessageReceived);
Client.Connect("localhost", 9999);
Client.Connect("localhost", port);
}
catch (Exception)
{
@@ -137,7 +138,6 @@ static void Main(String[] args)
Server.OnClientMessageReceived += new BaseMessageServer.MessageReceivedHandler(Server_OnClientMessageReceived);
Server.OnClientAfterConnect += new TCPLibrary.Core.Server.ConnectedHandler(Server_OnClientAfterConnect);
Server.OnClientAfterDisconnected += new TCPLibrary.Core.Server.DisconnectedHandler(Server_OnClientAfterDisconnected);
Server.Port = 9999;
Server.Enabled = true;

Application.EnableVisualStyles();
@@ -238,6 +238,7 @@ private void ExecuteFunction(String Function)
if (lstDumps.SelectedItem != null)
DumpPath = Properties.Settings.Default.DumpDir + "\\" +
lstDumps.SelectedItem.ToString().Split(new char[] { '|' })[0];
var port = Program.Server.Port;

// Start the child and link the events.
ProcessStartInfo psi = new ProcessStartInfo();
@@ -246,7 +247,7 @@ private void ExecuteFunction(String Function)
psi.RedirectStandardError = false;
psi.CreateNoWindow = true;
psi.FileName = Process.GetCurrentProcess().ProcessName;
psi.Arguments = "\"" + DLLPath + "\"" + " \"" + DumpPath + "\"" + " \"" + Function + "\"" + " " + SelectedRenderer;
psi.Arguments = "\"" + DLLPath + "\"" + " \"" + DumpPath + "\"" + " \"" + Function + "\"" + " " + SelectedRenderer + " " + port;
Process p = Process.Start(psi);
p.OutputDataReceived += new DataReceivedEventHandler(p_OutputDataReceived);
p.BeginOutputReadLine();
@@ -42,10 +42,6 @@ public class Server
/// </summary>
private TcpListener _socket;
/// <summary>
/// Port to which the server will listen.
/// </summary>
private Int32 _port;
/// <summary>
/// Whether the server is enabled or not.
/// </summary>
private Boolean _enabled;
@@ -132,13 +128,11 @@ public class Server
/// <exception cref="TCPLibrary.Core.ServerAttivoException" />
public Int32 Port
{
get { return _port; }
set
get
{
if (Enabled == false)
_port = value;
else
throw new ArgumentException("Impossibile eseguire l'operazione a server attivo");
if (Enabled)
return ((IPEndPoint) _socket.LocalEndpoint).Port;
throw new NotSupportedException("Server is not running and hence has no port.");
}
}

@@ -212,10 +206,10 @@ protected virtual void DeactivateServer()
/// </summary>
protected virtual void ActivateServer()
{
_socket = new TcpListener(IPAddress.Any, Port);
_socket = new TcpListener(IPAddress.Any, 0);
_socket.Start(ConnectionBackLog);
Thread thd = new Thread(new ThreadStart(MainThread));
thd.Name = "Server on port " + Port.ToString();
thd.Name = "Server on port " + ((IPEndPoint) _socket.LocalEndpoint).Port;
thd.IsBackground = true;
thd.Start();
_enabled = true;
@@ -249,7 +243,6 @@ public void Broadcast(Data Data)
public Server()
{
_clients = new List<ClientS>();
_port = 0;
_connectionbacklog = 0;
_enabled = false;
}

0 comments on commit 48b2383

Please sign in to comment.
You can’t perform that action at this time.