Skip to content

Commit

Permalink
Some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
LumpBloom7 committed Sep 21, 2021
1 parent eaa8cd5 commit 0cb36a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public TestSceneGameplayEventBroadcaster()
AddStep("Send message 3", () => broadcaster.Broadcast(new TransmissionData(TransmissionData.InfoType.Miss, 3)));
AddAssert("Client received message 3", () => text.Text == new TransmissionData(TransmissionData.InfoType.Miss, 3).ToString());
AddStep("Dispose broadcaster", () => broadcaster.Dispose());
AddStep("Dispose client", () => client?.Dispose());
}

protected override void Dispose(bool isDisposing)
Expand All @@ -42,15 +43,15 @@ protected override void Dispose(bool isDisposing)

private class TestBroadcastClient : IDisposable
{
private NamedPipeClientStream pipeServer;
private readonly NamedPipeClientStream pipeServer;

private SpriteText text;
private readonly SpriteText text;

private bool running = true;

public bool IsClientConnected => pipeServer.IsConnected;

private Thread readThread;
private readonly Thread readThread;

public TestBroadcastClient(SpriteText outputText)
{
Expand All @@ -63,7 +64,7 @@ public TestBroadcastClient(SpriteText outputText)
readThread.Start();
}

private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
private CancellationToken cancellationToken => cancellationTokenSource.Token;

private void clientLoop()
Expand Down
18 changes: 9 additions & 9 deletions osu.Game.Rulesets.Sentakki/IO/GameplayEventBroadcaster.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.IO.Pipes;

namespace osu.Game.Rulesets.Sentakki.IO
Expand Down Expand Up @@ -35,18 +36,16 @@ private void waitForConnectionCallBack(IAsyncResult result)
{
pipeServer.EndWaitForConnection(result);
isWaitingForClient = false;

if (queuedData != TransmissionData.Empty)
Broadcast(queuedData);
}
catch
catch (IOException)
{
// If the pipe is closed before a client ever connects,
// EndWaitForConnection() will throw an exception.

// If we are in here that is probably the case so just return.
// The server has been disposed, abort wait
return;
}

if (queuedData != TransmissionData.Empty)
Broadcast(queuedData);

}

public void Broadcast(TransmissionData packet)
Expand All @@ -66,8 +65,9 @@ private bool connectionValid()
if (isWaitingForClient) return false;

try { pipeServer.WriteByte(0); }
catch
catch (IOException)
{
// The client has suddenly disconnected, we must disconnect on our end, and wait for a new connection.
pipeServer.Disconnect();
onClientDisconnected();

Expand Down

0 comments on commit 0cb36a2

Please sign in to comment.