Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make IPC port configurable via HostOptions #6129

Merged
merged 5 commits into from
Jan 15, 2024
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
4 changes: 2 additions & 2 deletions osu.Framework.Tests/Platform/HeadlessGameHostTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public void TestThreadSafetyResetOnEnteringThread()
[Test]
public void TestIpc()
{
using (var server = new BackgroundGameHeadlessGameHost(@"server", new HostOptions { BindIPC = true }))
using (var client = new HeadlessGameHost(@"client", new HostOptions { BindIPC = true }))
using (var server = new BackgroundGameHeadlessGameHost(@"server", new HostOptions { IPCPort = 45356 }))
using (var client = new HeadlessGameHost(@"client", new HostOptions { IPCPort = 45356 }))
{
Assert.IsTrue(server.IsPrimaryInstance, @"Server wasn't able to bind");
Assert.IsFalse(client.IsPrimaryInstance, @"Client was able to bind when it shouldn't have been able to");
Expand Down
6 changes: 3 additions & 3 deletions osu.Framework.Tests/Platform/UserInputManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class UserInputManagerTest
[Test]
public void IsAliveTest()
{
using (var client = new TestHeadlessGameHost(@"client", true))
using (var client = new TestHeadlessGameHost(@"client", 45356))
{
var testGame = new TestTestGame();
client.Run(testGame);
Expand All @@ -25,8 +25,8 @@ private class TestHeadlessGameHost : TestRunHeadlessGameHost
{
public Drawable CurrentRoot => Root;

public TestHeadlessGameHost(string gameName, bool bindIPC)
: base(gameName, new HostOptions { BindIPC = bindIPC })
public TestHeadlessGameHost(string gameName, int? ipcPort)
: base(gameName, new HostOptions { IPCPort = ipcPort })
{
}
}
Expand Down
7 changes: 5 additions & 2 deletions osu.Framework/HostOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ namespace osu.Framework
public class HostOptions
{
/// <summary>
/// Whether to bind the IPC port. See <see cref="IIpcHost"/> for more details on usage.
/// 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.
/// See <see cref="IIpcHost"/> for more details on usage.
/// </summary>
public bool BindIPC { get; set; }
public int? IPCPort { 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.
Expand Down
10 changes: 4 additions & 6 deletions osu.Framework/Platform/DesktopGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ namespace osu.Framework.Platform
{
public abstract class DesktopGameHost : SDL2GameHost
{
public const int IPC_PORT = 45356;

private TcpIpcProvider ipcProvider;
private readonly bool bindIPCPort;
private readonly int? ipcPort;

protected DesktopGameHost(string gameName, HostOptions options = null)
: base(gameName, options)
{
bindIPCPort = Options.BindIPC;
ipcPort = Options.IPCPort;
IsPortableInstallation = Options.PortableInstallation;
}

Expand Down Expand Up @@ -57,13 +55,13 @@ protected override void SetupForRun()

private void ensureIPCReady()
{
if (!bindIPCPort)
if (ipcPort == null)
return;

if (ipcProvider != null)
return;

ipcProvider = new TcpIpcProvider(IPC_PORT);
ipcProvider = new TcpIpcProvider(ipcPort.Value);
ipcProvider.MessageReceived += OnMessageReceived;

IsPrimaryInstance = ipcProvider.Bind();
Expand Down
Loading