Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Marsey/IPC/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public string ConnRecv(string name)

try
{
pipeClient.Connect(150); // Pipe should connect immediately
pipeClient.Connect(2000);
}
catch(TimeoutException)
{
Expand Down
32 changes: 23 additions & 9 deletions Marsey/IPC/Server.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO.Pipes;
using System.IO.Pipes;
using System.Text;
using Marsey.Misc;

Expand All @@ -17,20 +17,15 @@ public async Task ReadySend(string name, string data)
{
MarseyLogger.Log(MarseyLogger.LogType.INFO, "IPC-SERVER", $"Opening {name} (attempt {attempt}/{maxAttempts})");

await using NamedPipeServerStream pipeServer = new NamedPipeServerStream(
var pipeServer = new NamedPipeServerStream(
name,
PipeDirection.Out,
NamedPipeServerStream.MaxAllowedServerInstances,
PipeTransmissionMode.Byte,
PipeOptions.Asynchronous);

await pipeServer.WaitForConnectionAsync();

byte[] buffer = Encoding.UTF8.GetBytes(data);
await pipeServer.WriteAsync(buffer);

MarseyLogger.Log(MarseyLogger.LogType.INFO, "IPC-SERVER", $"Closing {name}");
pipeServer.Close();
var wait = pipeServer.WaitForConnectionAsync();
_ = SendWhenConnected(pipeServer, wait, name, data);
return;
}
catch (IOException ex) when (attempt < maxAttempts)
Expand All @@ -42,4 +37,23 @@ public async Task ReadySend(string name, string data)

MarseyLogger.Log(MarseyLogger.LogType.ERRO, "IPC-SERVER", $"Failed to open pipe {name}: all attempts exhausted.");
}

private static async Task SendWhenConnected(NamedPipeServerStream pipeServer, Task wait, string name, string data)
{
try
{
await wait;
byte[] buffer = Encoding.UTF8.GetBytes(data);
await pipeServer.WriteAsync(buffer);
MarseyLogger.Log(MarseyLogger.LogType.INFO, "IPC-SERVER", $"Closing {name}");
}
catch (Exception ex)
{
MarseyLogger.Log(MarseyLogger.LogType.ERRO, "IPC-SERVER", $"Failed to send {name}: {ex.Message}");
}
finally
{
await pipeServer.DisposeAsync();
}
}
}
16 changes: 7 additions & 9 deletions SS14.Launcher/Models/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,16 +650,14 @@ private async Task<ContentLaunchInfo> InstallContentBundleAsync(
return null;
}

// Prepare IPC pipes for Marsey without blocking process start.
// Pipes must be opened before/around launch, but awaiting here deadlocks
// because the loader is the one that connects to them.
_ = Marsify().ContinueWith(t =>
try
{
if (t.Exception != null)
{
Log.Error(t.Exception, "Marsey IPC preparation failed");
}
}, TaskScheduler.Default);
await Marsify();
}
catch (Exception e)
{
Log.Error(e, "Marsey IPC preparation failed");
}

ConfigureEnvironmentVariables(startInfo, launchInfo, engineVersion);
ConfigureLogging(startInfo);
Expand Down
Loading