Exemple #1
0
        public static Stream Connect(IpcEndpointConfig config, TimeSpan timeout)
        {
            if (config.Transport == IpcEndpointConfig.TransportType.NamedPipe)
            {
                var namedPipe = new NamedPipeClientStream(
                    ".",
                    config.Address,
                    PipeDirection.InOut,
                    PipeOptions.None,
                    TokenImpersonationLevel.Impersonation);
                namedPipe.Connect((int)timeout.TotalMilliseconds);
                return(namedPipe);
            }
            else if (config.Transport == IpcEndpointConfig.TransportType.UnixDomainSocket)
            {
                var socket = new IpcUnixDomainSocket();
                socket.Connect(new IpcUnixDomainSocketEndPoint(config.Address), timeout);
                return(new ExposedSocketNetworkStream(socket, ownsSocket: true));
            }
#if DIAGNOSTICS_RUNTIME
            else if (config.Transport == IpcEndpointConfig.TransportType.TcpSocket)
            {
                var tcpClient = new TcpClient();
                var endPoint  = new IpcTcpSocketEndPoint(config.Address);
                tcpClient.Connect(endPoint.EndPoint);
                return(tcpClient.GetStream());
            }
#endif
            else
            {
                throw new ArgumentException($"Unsupported IpcEndpointConfig transport type {config.Transport}");
            }
        }
Exemple #2
0
        public static async Task <Stream> ConnectAsync(IpcEndpointConfig config, CancellationToken token)
        {
            if (config.Transport == IpcEndpointConfig.TransportType.NamedPipe)
            {
                var namedPipe = new NamedPipeClientStream(
                    ".",
                    config.Address,
                    PipeDirection.InOut,
                    PipeOptions.Asynchronous,
                    TokenImpersonationLevel.Impersonation);

                // Pass non-infinite timeout in order to cause internal connection algorithm
                // to check the CancellationToken periodically. Otherwise, if the named pipe
                // is waited using WaitNamedPipe with an infinite timeout, then the
                // CancellationToken cannot be observed.
                await namedPipe.ConnectAsync(int.MaxValue, token).ConfigureAwait(false);

                return(namedPipe);
            }
            else if (config.Transport == IpcEndpointConfig.TransportType.UnixDomainSocket)
            {
                var socket = new IpcUnixDomainSocket();
                await socket.ConnectAsync(new IpcUnixDomainSocketEndPoint(config.Address), token).ConfigureAwait(false);

                return(new ExposedSocketNetworkStream(socket, ownsSocket: true));
            }
            else
            {
                throw new ArgumentException($"Unsupported IpcEndpointConfig transport type {config.Transport}");
            }
        }
Exemple #3
0
        public override Stream Connect(TimeSpan timeout)
        {
            string address = GetDefaultAddress();

            _config = IpcEndpointConfig.Parse(address + ",connect");
            return(IpcEndpointHelper.Connect(_config, timeout));
        }
Exemple #4
0
        public override async Task <Stream> ConnectAsync(CancellationToken token)
        {
            string address = GetDefaultAddress();

            _config = IpcEndpointConfig.Parse(address + ",connect");
            return(await IpcEndpointHelper.ConnectAsync(_config, token).ConfigureAwait(false));
        }
        public static async Task <Stream> ConnectAsync(IpcEndpointConfig config, CancellationToken token)
        {
            if (config.Transport == IpcEndpointConfig.TransportType.NamedPipe)
            {
                var namedPipe = new NamedPipeClientStream(
                    ".",
                    config.Address,
                    PipeDirection.InOut,
                    PipeOptions.Asynchronous,
                    TokenImpersonationLevel.Impersonation);
                await namedPipe.ConnectAsync(token).ConfigureAwait(false);

                return(namedPipe);
            }
            else if (config.Transport == IpcEndpointConfig.TransportType.UnixDomainSocket)
            {
                var socket = new IpcUnixDomainSocket();
                await socket.ConnectAsync(new IpcUnixDomainSocketEndPoint(config.Address), token).ConfigureAwait(false);

                return(new ExposedSocketNetworkStream(socket, ownsSocket: true));
            }
            else
            {
                throw new ArgumentException($"Unsupported IpcEndpointConfig transport type {config.Transport}");
            }
        }
Exemple #6
0
 // Config format: [Address],[PortType]
 //
 // Address in UnixDomainSocket formats:
 // myport => myport
 // uds:myport => myport
 // /User/mrx/myport.sock => /User/mrx/myport.sock
 // uds:/User/mrx/myport.sock => /User/mrx/myport.sock
 // uds://authority/User/mrx/myport.sock => /User/mrx/myport.sock
 // uds:///User/mrx/myport.sock => /User/mrx/myport.sock
 //
 // Address in NamedPipe formats:
 // myport => myport
 // namedpipe:myport => myport
 // \\.\pipe\myport => myport (dropping \\.\pipe\ is inline with implemented namedpipe client/server)
 // namedpipe://./pipe/myport => myport (dropping authority and /pipe/ is inline with implemented namedpipe client/server)
 // namedpipe:/pipe/myport  => myport (dropping /pipe/ is inline with implemented namedpipe client/server)
 // namedpipe://authority/myport => myport
 // namedpipe:///myport => myport
 //
 // PortType: Listen|Connect, default Listen.
 public static bool TryParse(string config, out IpcEndpointConfig result)
 {
     try
     {
         result = Parse(config);
     }
     catch (Exception)
     {
         result = null;
     }
     return(result != null);
 }
Exemple #7
0
 public DiagnosticPortIpcEndpoint(IpcEndpointConfig config)
 {
     _config = config;
 }
Exemple #8
0
 public DiagnosticPortIpcEndpoint(string diagnosticPort)
 {
     _config = IpcEndpointConfig.Parse(diagnosticPort);
 }
 internal DiagnosticsClient(IpcEndpointConfig config) :
     this(new DiagnosticPortIpcEndpoint(config))
 {
 }