From f0e2b92d51bd730bbe1c7bfa7f117587bc26fd73 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 3 Dec 2024 15:17:41 +0900 Subject: [PATCH] Switch to using pipe name instead of port number --- osu.Framework/HostOptions.cs | 18 ++++++++++++++---- osu.Framework/Platform/DesktopGameHost.cs | 8 ++++---- osu.Framework/Platform/NamedPipeIpcProvider.cs | 14 +++++++------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/osu.Framework/HostOptions.cs b/osu.Framework/HostOptions.cs index c6e7d4dc2..43042479f 100644 --- a/osu.Framework/HostOptions.cs +++ b/osu.Framework/HostOptions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; +using System.Globalization; using osu.Framework.Platform; namespace osu.Framework @@ -11,12 +13,20 @@ namespace osu.Framework public class HostOptions { /// - /// The IPC port to bind. This port should be between 1024 and 49151, - /// should be shared by all instances of a given osu!framework app, - /// but be distinct from IPC ports specified by other osu!framework apps. + /// Use instead. + /// + [Obsolete("Use IPCPipeName instead.")] // can be removed 20250603. + public int? IPCPort + { + set => IPCPipeName = value?.ToString(CultureInfo.InvariantCulture); + } + + /// + /// The IPC pipe name to bind. This should be shared by all instances of + /// an osu!framework app that want to perform inter-process communications. /// See for more details on usage. /// - public int? IPCPort { get; set; } + public string? IPCPipeName { get; set; } /// /// Whether this is a portable installation. Will cause all game files to be placed alongside the executable, rather than in the standard data directory. diff --git a/osu.Framework/Platform/DesktopGameHost.cs b/osu.Framework/Platform/DesktopGameHost.cs index 0bde7dee1..b816040e1 100644 --- a/osu.Framework/Platform/DesktopGameHost.cs +++ b/osu.Framework/Platform/DesktopGameHost.cs @@ -16,12 +16,12 @@ namespace osu.Framework.Platform public abstract class DesktopGameHost : SDLGameHost { private NamedPipeIpcProvider ipcProvider; - private readonly int? ipcPort; + private readonly string ipcPipeName; protected DesktopGameHost(string gameName, HostOptions options = null) : base(gameName, options) { - ipcPort = Options.IPCPort; + ipcPipeName = Options.IPCPipeName; IsPortableInstallation = Options.PortableInstallation; } @@ -55,13 +55,13 @@ namespace osu.Framework.Platform private void ensureIPCReady() { - if (ipcPort == null) + if (ipcPipeName == null) return; if (ipcProvider != null) return; - ipcProvider = new NamedPipeIpcProvider(ipcPort.Value); + ipcProvider = new NamedPipeIpcProvider(ipcPipeName); ipcProvider.MessageReceived += OnMessageReceived; IsPrimaryInstance = ipcProvider.Bind(); diff --git a/osu.Framework/Platform/NamedPipeIpcProvider.cs b/osu.Framework/Platform/NamedPipeIpcProvider.cs index d0631ab8d..6d270b126 100644 --- a/osu.Framework/Platform/NamedPipeIpcProvider.cs +++ b/osu.Framework/Platform/NamedPipeIpcProvider.cs @@ -28,7 +28,7 @@ namespace osu.Framework.Platform private readonly CancellationTokenSource cancellationSource = new CancellationTokenSource(); - private readonly int port; + private readonly string pipeName; private Task? listenTask; @@ -37,10 +37,10 @@ namespace osu.Framework.Platform /// /// Create a new provider. /// - /// The port to operate on. - public NamedPipeIpcProvider(int port) + /// The port to operate on. + public NamedPipeIpcProvider(string pipeName) { - this.port = port; + this.pipeName = pipeName; } /// @@ -57,7 +57,7 @@ namespace osu.Framework.Platform try { - pipe = new NamedPipeServerStream($"osu-framework-{port}", PipeDirection.InOut); + pipe = new NamedPipeServerStream($"osu-framework-{pipeName}", PipeDirection.InOut); listenTask = listen(pipe); @@ -119,7 +119,7 @@ namespace osu.Framework.Platform /// The message to send. public async Task SendMessageAsync(IpcMessage message) { - using (var client = new NamedPipeClientStream($"osu-framework-{port}")) + using (var client = new NamedPipeClientStream($"osu-framework-{pipeName}")) { await client.ConnectAsync().ConfigureAwait(false); await send(client, message).ConfigureAwait(false); @@ -133,7 +133,7 @@ namespace osu.Framework.Platform /// The response from the server. public async Task SendMessageWithResponseAsync(IpcMessage message) { - using (var client = new NamedPipeClientStream($"osu-framework-{port}")) + using (var client = new NamedPipeClientStream($"osu-framework-{pipeName}")) { await client.ConnectAsync().ConfigureAwait(false); await send(client, message).ConfigureAwait(false);