diff --git a/src/BizHawk.Client.Common/Api/ClientWebSocketWrapper.cs b/src/BizHawk.Client.Common/Api/ClientWebSocketWrapper.cs
index 60681a4278..26717757fe 100644
--- a/src/BizHawk.Client.Common/Api/ClientWebSocketWrapper.cs
+++ b/src/BizHawk.Client.Common/Api/ClientWebSocketWrapper.cs
@@ -14,52 +14,67 @@ namespace BizHawk.Client.Common
/// calls getter (unless closed/disposed, then is always returned)
public WebSocketState State => _w?.State ?? WebSocketState.Closed;
- public ClientWebSocketWrapper(Uri uri, CancellationToken? cancellationToken = null)
+ public ClientWebSocketWrapper(
+ Uri uri,
+ CancellationToken cancellationToken = default/* == CancellationToken.None */)
{
- cancellationToken ??= CancellationToken.None;
_w = new ClientWebSocket();
- _w.ConnectAsync(uri, cancellationToken.Value).Wait(cancellationToken.Value);
+ _w.ConnectAsync(uri, cancellationToken).Wait(cancellationToken);
}
/// calls
/// also calls (wrapper property will continue to work, method calls will throw )
- public Task Close(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken? cancellationToken = null)
+ public Task Close(
+ WebSocketCloseStatus closeStatus,
+ string statusDescription,
+ CancellationToken cancellationToken = default/* == CancellationToken.None */)
{
if (_w == null) throw new ObjectDisposedException(nameof(_w));
- var task = _w.CloseAsync(closeStatus, statusDescription, cancellationToken ?? CancellationToken.None);
+ var task = _w.CloseAsync(closeStatus, statusDescription, cancellationToken);
_w.Dispose();
_w = null;
return task;
}
/// calls
- public Task Receive(ArraySegment buffer, CancellationToken? cancellationToken = null)
- => _w?.ReceiveAsync(buffer, cancellationToken ?? CancellationToken.None)
- ?? throw new ObjectDisposedException(nameof(_w));
+ public Task Receive(
+ ArraySegment buffer,
+ CancellationToken cancellationToken = default/* == CancellationToken.None */)
+ => _w?.ReceiveAsync(buffer, cancellationToken)
+ ?? throw new ObjectDisposedException(nameof(_w));
/// calls
- public string Receive(int bufferCap, CancellationToken? cancellationToken = null)
+ public string Receive(
+ int bufferCap,
+ CancellationToken cancellationToken = default/* == CancellationToken.None */)
{
if (_w == null) throw new ObjectDisposedException(nameof(_w));
var buffer = new byte[bufferCap];
- var result = Receive(new ArraySegment(buffer), cancellationToken ?? CancellationToken.None).Result;
+ var result = Receive(new ArraySegment(buffer), cancellationToken).Result;
return Encoding.UTF8.GetString(buffer, 0, result.Count);
}
/// calls
- public Task Send(ArraySegment buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken? cancellationToken = null)
- => _w?.SendAsync(buffer, messageType, endOfMessage, cancellationToken ?? CancellationToken.None)
- ?? throw new ObjectDisposedException(nameof(_w));
+ public Task Send(
+ ArraySegment buffer,
+ WebSocketMessageType messageType,
+ bool endOfMessage,
+ CancellationToken cancellationToken = default/* == CancellationToken.None */)
+ => _w?.SendAsync(buffer, messageType, endOfMessage, cancellationToken)
+ ?? throw new ObjectDisposedException(nameof(_w));
/// calls
- public Task Send(string message, bool endOfMessage, CancellationToken? cancellationToken = null)
+ public Task Send(
+ string message,
+ bool endOfMessage,
+ CancellationToken cancellationToken = default/* == CancellationToken.None */)
{
if (_w == null) throw new ObjectDisposedException(nameof(_w));
return Send(
new ArraySegment(Encoding.UTF8.GetBytes(message)),
WebSocketMessageType.Text,
endOfMessage,
- cancellationToken ?? CancellationToken.None
+ cancellationToken
);
}
}
diff --git a/src/BizHawk.Client.Common/Api/WebSocketServer.cs b/src/BizHawk.Client.Common/Api/WebSocketServer.cs
index be68f7c51d..a887b83227 100644
--- a/src/BizHawk.Client.Common/Api/WebSocketServer.cs
+++ b/src/BizHawk.Client.Common/Api/WebSocketServer.cs
@@ -6,6 +6,9 @@ namespace BizHawk.Client.Common
{
public sealed class WebSocketServer
{
- public ClientWebSocketWrapper Open(Uri uri, CancellationToken? cancellationToken = null) => new ClientWebSocketWrapper(uri, cancellationToken);
+ public ClientWebSocketWrapper Open(
+ Uri uri,
+ CancellationToken cancellationToken = default/* == CancellationToken.None */)
+ => new(uri, cancellationToken);
}
}