[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
This commit is contained in:
willkuer 2019-04-14 12:04:58 +02:00 committed by lightningterror
parent 075a9f38ed
commit 48b2383096
3 changed files with 11 additions and 17 deletions

View File

@ -52,16 +52,17 @@ namespace GSDumpGUI
[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 @@ namespace GSDumpGUI
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();

View File

@ -238,6 +238,7 @@ namespace GSDumpGUI
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 @@ namespace GSDumpGUI
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();

View File

@ -42,10 +42,6 @@ namespace TCPLibrary.Core
/// </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 @@ namespace TCPLibrary.Core
/// <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 @@ namespace TCPLibrary.Core
/// </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 @@ namespace TCPLibrary.Core
public Server()
{
_clients = new List<ClientS>();
_port = 0;
_connectionbacklog = 0;
_enabled = false;
}