Skip to content

Commit a887076

Browse files
committed
optimize: use Uri parse endpoint
1 parent 6480ed4 commit a887076

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

src/Plugins/SignClient/Settings.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,8 @@ public static Settings Default
7878
{
7979
if (EndpointType != EndpointVsock) return null;
8080

81-
var endpoint = Endpoint;
82-
if (Endpoint.StartsWith("http://"))
83-
{
84-
endpoint = endpoint.Substring("http://".Length);
85-
}
86-
else if (Endpoint.StartsWith("https://"))
87-
{
88-
endpoint = endpoint.Substring("https://".Length);
89-
}
90-
91-
var parts = endpoint.Split(':', 2);
81+
var uri = new Uri(Endpoint); // UriFormatException is a subclass of FormatException
82+
var parts = uri.Host.Split(':', 2);
9283
if (parts.Length != 2) throw new FormatException($"Invalid vsock endpoint: {Endpoint}");
9384
try
9485
{

src/Plugins/SignClient/Vsock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public Vsock(VsockAddress address)
4040
_endpoint = new VSockEndPoint(address.ContextId, address.Port);
4141
}
4242

43-
internal async ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken)
43+
internal async ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellation)
4444
{
4545
if (!OperatingSystem.IsLinux()) throw new PlatformNotSupportedException("Vsock is only supported on Linux.");
4646

4747
var socket = VSock.Create(SocketType.Stream);
4848
try
4949
{
5050
// Have to use `Task.Run` with `Connect` to avoid some compatibility issues(if use ConnectAsync).
51-
await Task.Run(() => socket.Connect(_endpoint), cancellationToken);
51+
await Task.Run(() => socket.Connect(_endpoint), cancellation);
5252
return new NetworkStream(socket, true);
5353
}
5454
catch

0 commit comments

Comments
 (0)