# < Summary

Information

Class: | Renci.SshNet.Connection.ProxyConnector
Assembly: | Renci.SshNet
File(s): | \home\appveyor\projects\ssh-net\src\Renci.SshNet\Connection\ProxyConnector.cs

Line coverage
47%

Covered lines: | 16
Uncovered lines: | 18
Coverable lines: | 34
Total lines: | 97
Line coverage: | 47%

Branch coverage
N/A

Covered branches: | 0
Total branches: | 0
Branch coverage: | N/A

Method coverage

Feature is only available for sponsors

Upgrade to PRO version

# Metrics

Method | Branch coverage | Cyclomatic complexity | Line coverage
--- | --- | --- | ---
.ctor(...) | 100% | 1 | 100%
HandleProxyConnectAsync() | 100% | 1 | 0%
HandleProxyConnectAsync(...) | 100% | 1 | 0%
Connect(...) | 100% | 1 | 100%
ConnectAsync() | 100% | 1 | 18.18%

# File(s)

## \home\appveyor\projects\ssh-net\src\Renci.SshNet\Connection\ProxyConnector.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.Net.Sockets;`
|  | `3` |  | `using System.Threading;`
|  | `4` |  | `using System.Threading.Tasks;`
|  | `5` |  | ``
|  | `6` |  | `namespace Renci.SshNet.Connection`
|  | `7` |  | `{`
|  | `8` |  | `/// <summary>`
|  | `9` |  | `/// Represents a connector that uses a proxy server to establish a connection to a given SSH`
|  | `10` |  | `/// endpoint.`
|  | `11` |  | `/// </summary>`
|  | `12` |  | `internal abstract class ProxyConnector : ConnectorBase`
|  | `13` |  | `{`
|  | `14` |  | `protected ProxyConnector(ISocketFactory socketFactory)`
| 429 | `15` |  | `: base(socketFactory)`
| 429 | `16` |  | `{`
| 429 | `17` |  | `}`
|  | `18` |  | ``
|  | `19` |  | `protected abstract void HandleProxyConnect(IConnectionInfo connectionInfo, Socket socket);`
|  | `20` |  | ``
|  | `21` |  | `// ToDo: Performs async/sync fallback, true async version should be implemented in derived classes`
|  | `22` |  | `protected virtual`
|  | `23` |  | `#if NET || NETSTANDARD2_1_OR_GREATER`
|  | `24` |  | `async`
|  | `25` |  | `#endif // NET || NETSTANDARD2_1_OR_GREATER`
|  | `26` |  | `Task HandleProxyConnectAsync(IConnectionInfo connectionInfo, Socket socket, CancellationToken cancellationToken)`
| 0 | `27` |  | `{`
| 0 | `28` |  | `cancellationToken.ThrowIfCancellationRequested();`
|  | `29` |  | ``
|  | `30` |  | `#if NET || NETSTANDARD2_1_OR_GREATER`
| 0 | `31` |  | `await using (cancellationToken.Register(o => ((Socket)o).Dispose(), socket, useSynchronizationContext: false`
|  | `32` |  | `#else`
| 0 | `33` |  | `using (cancellationToken.Register(o => ((Socket) o).Dispose(), socket, useSynchronizationContext: false))`
|  | `34` |  | `#endif // NET || NETSTANDARD2_1_OR_GREATER`
| 0 | `35` |  | `{`
|  | `36` |  | `#pragma warning disable MA0042 // Do not use blocking calls in an async method; false positive caused by https://github.`
| 0 | `37` |  | `HandleProxyConnect(connectionInfo, socket);`
|  | `38` |  | `#pragma warning restore MA0042 // Do not use blocking calls in an async method`
| 0 | `39` |  | `}`
|  | `40` |  | ``
|  | `41` |  | `#if !NET && !NETSTANDARD2_1_OR_GREATER`
| 0 | `42` |  | `return Task.CompletedTask;`
|  | `43` |  | `#endif // !NET && !NETSTANDARD2_1_OR_GREATER`
| 0 | `44` |  | `}`
|  | `45` |  | ``
|  | `46` |  | `/// <summary>`
|  | `47` |  | `/// Connects to a SSH endpoint using the specified <see cref="IConnectionInfo"/>.`
|  | `48` |  | `/// </summary>`
|  | `49` |  | `/// <param name="connectionInfo">The <see cref="IConnectionInfo"/> to use to establish a connection to a SSH end`
|  | `50` |  | `/// <returns>`
|  | `51` |  | `/// A <see cref="Socket"/> connected to the SSH endpoint represented by the specified <see cref="IConnectionInfo`
|  | `52` |  | `/// </returns>`
|  | `53` |  | `public override Socket Connect(IConnectionInfo connectionInfo)`
| 417 | `54` |  | `{`
| 417 | `55` |  | `var socket = SocketConnect(connectionInfo.ProxyHost, connectionInfo.ProxyPort, connectionInfo.Timeout);`
|  | `56` |  | ``
|  | `57` |  | `try`
| 348 | `58` |  | `{`
| 348 | `59` |  | `HandleProxyConnect(connectionInfo, socket);`
| 165 | `60` |  | `return socket;`
|  | `61` |  | `}`
| 183 | `62` |  | `catch (Exception)`
| 183 | `63` |  | `{`
| 183 | `64` |  | `socket.Shutdown(SocketShutdown.Both);`
| 183 | `65` |  | `socket.Dispose();`
|  | `66` |  | ``
| 183 | `67` |  | `throw;`
|  | `68` |  | `}`
| 165 | `69` |  | `}`
|  | `70` |  | ``
|  | `71` |  | `/// <summary>`
|  | `72` |  | `/// Asynchronously connects to a SSH endpoint using the specified <see cref="IConnectionInfo"/>.`
|  | `73` |  | `/// </summary>`
|  | `74` |  | `/// <param name="connectionInfo">The <see cref="IConnectionInfo"/> to use to establish a connection to a SSH end`
|  | `75` |  | `/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>`
|  | `76` |  | `/// <returns>`
|  | `77` |  | `/// A <see cref="Socket"/> connected to the SSH endpoint represented by the specified <see cref="IConnectionInfo`
|  | `78` |  | `/// </returns>`
|  | `79` |  | `public override async Task<Socket> ConnectAsync(IConnectionInfo connectionInfo, CancellationToken cancellationTo`
| 3 | `80` |  | `{`
| 3 | `81` |  | `var socket = await SocketConnectAsync(connectionInfo.ProxyHost, connectionInfo.ProxyPort, cancellationToken)`
|  | `82` |  | ``
|  | `83` |  | `try`
| 0 | `84` |  | `{`
| 0 | `85` |  | `await HandleProxyConnectAsync(connectionInfo, socket, cancellationToken).ConfigureAwait(false);`
| 0 | `86` |  | `return socket;`
|  | `87` |  | `}`
| 0 | `88` |  | `catch (Exception)`
| 0 | `89` |  | `{`
| 0 | `90` |  | `socket.Shutdown(SocketShutdown.Both);`
| 0 | `91` |  | `socket.Dispose();`
|  | `92` |  | ``
| 0 | `93` |  | `throw;`
|  | `94` |  | `}`
| 0 | `95` |  | `}`
|  | `96` |  | `}`
|  | `97` |  | `}`

# Methods/Properties

.ctor(Renci.SshNet.Connection.ISocketFactory)
HandleProxyConnectAsync()
HandleProxyConnectAsync(Renci.SshNet.IConnectionInfo,System.Net.Sockets.Socket,System.Threading.CancellationToken)
Connect(Renci.SshNet.IConnectionInfo)
ConnectAsync()