Skip to content

Commit 54dfdff

Browse files
committed
Extend to DiagnosticsClient string constructor
1 parent 972fe7a commit 54dfdff

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/DiagnosticsClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ internal DiagnosticsClient(IpcEndpointConfig config) :
3030
{
3131
}
3232

33+
public DiagnosticsClient(string diagnosticPort) :
34+
this(new DiagnosticPortIpcEndpoint(diagnosticPort))
35+
{
36+
}
37+
3338
internal DiagnosticsClient(IpcEndpoint endpoint)
3439
{
3540
_endpoint = endpoint;
3641
}
3742

43+
3844
/// <summary>
3945
/// Wait for an available diagnostic endpoint to the runtime instance.
4046
/// </summary>

src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcEndpointConfig.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public enum PortType
1818
public enum TransportType
1919
{
2020
NamedPipe,
21-
UnixDomainSocket
21+
UnixDomainSocket,
22+
TcpClient
2223
}
2324

2425
PortType _portType;
@@ -57,6 +58,12 @@ public IpcEndpointConfig(string address, TransportType transportType, PortType p
5758
throw new PlatformNotSupportedException($"{UnixDomainSocketSchema} is not supported on Windows, use {NamedPipeSchema}.");
5859
break;
5960
}
61+
case TransportType.TcpClient:
62+
{
63+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
64+
throw new PlatformNotSupportedException($"TcpClient is not supported on Windows, use {NamedPipeSchema}.");
65+
break;
66+
}
6067
default:
6168
{
6269
throw new NotSupportedException($"{transportType} not supported.");
@@ -108,7 +115,7 @@ public static IpcEndpointConfig Parse(string config)
108115

109116
string address = "";
110117
PortType portType = PortType.Connect;
111-
TransportType transportType = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? TransportType.NamedPipe : TransportType.UnixDomainSocket;
118+
TransportType transportType = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? TransportType.NamedPipe : OperatingSystem.IsAndroid() ? TransportType.TcpClient : TransportType.UnixDomainSocket;
112119

113120
if (!string.IsNullOrEmpty(config))
114121
{

src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcTransport.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.IO;
88
using System.IO.Pipes;
99
using System.Linq;
10+
using System.Net.Sockets;
1011
using System.Runtime.InteropServices;
1112
using System.Security.Principal;
1213
using System.Threading;
@@ -69,6 +70,13 @@ public static Stream Connect(IpcEndpointConfig config, TimeSpan timeout)
6970
socket.Connect(new IpcUnixDomainSocketEndPoint(config.Address), timeout);
7071
return new ExposedSocketNetworkStream(socket, ownsSocket: true);
7172
}
73+
else if (config.Transport == IpcEndpointConfig.TransportType.TcpClient)
74+
{
75+
var addressPort = config.Address.Split(':');
76+
77+
TcpClient tcpClient = new TcpClient (addressPort[0], int.Parse(addressPort[1]));
78+
return tcpClient.GetStream();
79+
}
7280
else
7381
{
7482
throw new ArgumentException($"Unsupported IpcEndpointConfig transport type {config.Transport}");

0 commit comments

Comments
 (0)