diff --git a/Dalamud/Networking/Rpc/Transport/UnixRpcTransport.cs b/Dalamud/Networking/Rpc/Transport/UnixRpcTransport.cs index 064ce375d..17da51444 100644 --- a/Dalamud/Networking/Rpc/Transport/UnixRpcTransport.cs +++ b/Dalamud/Networking/Rpc/Transport/UnixRpcTransport.cs @@ -8,8 +8,6 @@ using System.Threading.Tasks; using Dalamud.Logging.Internal; using Dalamud.Utility; -using TerraFX.Interop.Windows; - namespace Dalamud.Networking.Rpc.Transport; /// @@ -94,13 +92,6 @@ internal class UnixRpcTransport : IRpcTransport } this.acceptLoopTask = Task.Factory.StartNew(this.AcceptLoopAsync, TaskCreationOptions.LongRunning); - - // note: needs to be run _after_ we're alive so that we don't delete our own socket. - // TODO: This should *probably* be handed by the launcher instead. - if (this.cleanupSocketDirectory != null) - { - Task.Run(async () => await UnixSocketUtil.CleanStaleSockets(this.cleanupSocketDirectory)); - } } /// Invoke an RPC request on a specific client expecting a result. diff --git a/Dalamud/Networking/Rpc/UnixSocketUtil.cs b/Dalamud/Networking/Rpc/UnixSocketUtil.cs deleted file mode 100644 index b7500a946..000000000 --- a/Dalamud/Networking/Rpc/UnixSocketUtil.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System.IO; -using System.Net.Sockets; -using System.Threading.Tasks; - -using Serilog; - -namespace Dalamud.Networking.Rpc; - -/// -/// A set of utilities to help manage Unix sockets. -/// -internal static class UnixSocketUtil -{ - // Default probe timeout in milliseconds. - private const int DefaultProbeMs = 200; - - /// - /// Test whether a Unix socket is alive/listening. - /// - /// The path to test. - /// How long to wait for a connection success. - /// A task result representing if a socket is alive or not. - public static async Task IsSocketAlive(string path, int timeoutMs = DefaultProbeMs) - { - if (string.IsNullOrEmpty(path)) return false; - var endpoint = new UnixDomainSocketEndPoint(path); - using var client = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); - - var connectTask = client.ConnectAsync(endpoint); - var completed = await Task.WhenAny(connectTask, Task.Delay(timeoutMs)).ConfigureAwait(false); - - if (completed == connectTask) - { - // Connected or failed very quickly. If the task is successful, the socket is alive. - if (connectTask.IsCompletedSuccessfully) - { - try - { - client.Shutdown(SocketShutdown.Both); - } - catch - { - // ignored - } - - return true; - } - } - - return false; - } - - /// - /// Find and remove stale Dalamud RPC sockets. - /// - /// The directory to scan for stale sockets. - /// The timeout to wait for a connection attempt to succeed. - /// A task that executes when sockets are purged. - public static async Task CleanStaleSockets(string directory, int probeTimeoutMs = DefaultProbeMs) - { - if (string.IsNullOrEmpty(directory) || !Directory.Exists(directory)) return; - - foreach (var file in Directory.EnumerateFiles(directory, "DalamudRPC.*.sock", SearchOption.TopDirectoryOnly)) - { - // we don't need to check ourselves. - if (file.Contains(Environment.ProcessId.ToString())) continue; - - bool shouldDelete; - - try - { - shouldDelete = !await IsSocketAlive(file, probeTimeoutMs); - } - catch - { - shouldDelete = true; - } - - if (shouldDelete) - { - try - { - File.Delete(file); - } - catch (Exception ex) - { - Log.Error(ex, "Could not delete stale socket file: {File}", file); - } - } - } - } -}