Skip to content

Commit

Permalink
Merge pull request #6129 from tsunyoku/configurable-ipc-port
Browse files Browse the repository at this point in the history
Make IPC port configurable via `HostOptions`
  • Loading branch information
bdach authored Jan 15, 2024
2 parents eaec94e + d5b513c commit 7cf027f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
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

0 comments on commit 7cf027f

Please sign in to comment.