Switch to using pipe name instead of port number

This commit is contained in:
Dean Herbert
2024-12-03 15:17:41 +09:00
parent 4f28716a7c
commit f0e2b92d51
3 changed files with 25 additions and 15 deletions

View File

@@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. 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
{
/// <summary>
/// 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 <see cref="IPCPipeName"/> instead.
/// </summary>
[Obsolete("Use IPCPipeName instead.")] // can be removed 20250603.
public int? IPCPort
{
set => IPCPipeName = value?.ToString(CultureInfo.InvariantCulture);
}
/// <summary>
/// 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 <see cref="IIpcHost"/> for more details on usage.
/// </summary>
public int? IPCPort { get; set; }
public string? IPCPipeName { get; set; }
/// <summary>
/// Whether this is a portable installation. Will cause all game files to be placed alongside the executable, rather than in the standard data directory.

View File

@@ -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();

View File

@@ -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
/// <summary>
/// Create a new provider.
/// </summary>
/// <param name="port">The port to operate on.</param>
public NamedPipeIpcProvider(int port)
/// <param name="pipeName">The port to operate on.</param>
public NamedPipeIpcProvider(string pipeName)
{
this.port = port;
this.pipeName = pipeName;
}
/// <summary>
@@ -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
/// <param name="message">The message to send.</param>
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
/// <returns>The response from the server.</returns>
public async Task<IpcMessage?> 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);