|
@@ -29,25 +29,21 @@ namespace Renci.SshNet.Connection
|
|
|
public abstract Task<Socket> ConnectAsync(IConnectionInfo connectionInfo, CancellationToken cancellationToken);
|
|
public abstract Task<Socket> ConnectAsync(IConnectionInfo connectionInfo, CancellationToken cancellationToken);
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// Establishes a socket connection to the specified host and port.
|
|
|
|
|
|
|
+ /// Establishes a socket connection to the specified endpoint.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- /// <param name="host">The host name of the server to connect to.</param>
|
|
|
|
|
- /// <param name="port">The port to connect to.</param>
|
|
|
|
|
|
|
+ /// <param name="endPoint">The <see cref="EndPoint"/> representing the server to connect to.</param>
|
|
|
/// <param name="timeout">The maximum time to wait for the connection to be established.</param>
|
|
/// <param name="timeout">The maximum time to wait for the connection to be established.</param>
|
|
|
/// <exception cref="SshOperationTimeoutException">The connection failed to establish within the configured <see cref="ConnectionInfo.Timeout"/>.</exception>
|
|
/// <exception cref="SshOperationTimeoutException">The connection failed to establish within the configured <see cref="ConnectionInfo.Timeout"/>.</exception>
|
|
|
/// <exception cref="SocketException">An error occurred trying to establish the connection.</exception>
|
|
/// <exception cref="SocketException">An error occurred trying to establish the connection.</exception>
|
|
|
- protected Socket SocketConnect(string host, int port, TimeSpan timeout)
|
|
|
|
|
|
|
+ protected Socket SocketConnect(EndPoint endPoint, TimeSpan timeout)
|
|
|
{
|
|
{
|
|
|
- var ipAddress = Dns.GetHostAddresses(host)[0];
|
|
|
|
|
- var ep = new IPEndPoint(ipAddress, port);
|
|
|
|
|
|
|
+ DiagnosticAbstraction.Log(string.Format("Initiating connection to '{0}'.", endPoint));
|
|
|
|
|
|
|
|
- DiagnosticAbstraction.Log(string.Format("Initiating connection to '{0}:{1}'.", host, port));
|
|
|
|
|
-
|
|
|
|
|
- var socket = SocketFactory.Create(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
|
|
|
|
|
|
+ var socket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
|
|
|
|
|
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
- SocketAbstraction.Connect(socket, ep, timeout);
|
|
|
|
|
|
|
+ SocketAbstraction.Connect(socket, endPoint, timeout);
|
|
|
|
|
|
|
|
const int socketBufferSize = 10 * Session.MaximumSshPacketSize;
|
|
const int socketBufferSize = 10 * Session.MaximumSshPacketSize;
|
|
|
socket.SendBufferSize = socketBufferSize;
|
|
socket.SendBufferSize = socketBufferSize;
|
|
@@ -62,31 +58,22 @@ namespace Renci.SshNet.Connection
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// Establishes a socket connection to the specified host and port.
|
|
|
|
|
|
|
+ /// Establishes a socket connection to the specified endpoint.
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- /// <param name="host">The host name of the server to connect to.</param>
|
|
|
|
|
- /// <param name="port">The port to connect to.</param>
|
|
|
|
|
|
|
+ /// <param name="endPoint">The <see cref="EndPoint"/> representing the server to connect to.</param>
|
|
|
/// <param name="cancellationToken">The cancellation token to observe.</param>
|
|
/// <param name="cancellationToken">The cancellation token to observe.</param>
|
|
|
/// <exception cref="SshOperationTimeoutException">The connection failed to establish within the configured <see cref="ConnectionInfo.Timeout"/>.</exception>
|
|
/// <exception cref="SshOperationTimeoutException">The connection failed to establish within the configured <see cref="ConnectionInfo.Timeout"/>.</exception>
|
|
|
/// <exception cref="SocketException">An error occurred trying to establish the connection.</exception>
|
|
/// <exception cref="SocketException">An error occurred trying to establish the connection.</exception>
|
|
|
- protected async Task<Socket> SocketConnectAsync(string host, int port, CancellationToken cancellationToken)
|
|
|
|
|
|
|
+ protected async Task<Socket> SocketConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)
|
|
|
{
|
|
{
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
|
|
-#if NET6_0_OR_GREATER
|
|
|
|
|
- var ipAddress = (await Dns.GetHostAddressesAsync(host, cancellationToken).ConfigureAwait(false))[0];
|
|
|
|
|
-#else
|
|
|
|
|
- var ipAddress = (await Dns.GetHostAddressesAsync(host).ConfigureAwait(false))[0];
|
|
|
|
|
-#endif
|
|
|
|
|
-
|
|
|
|
|
- var ep = new IPEndPoint(ipAddress, port);
|
|
|
|
|
-
|
|
|
|
|
- DiagnosticAbstraction.Log(string.Format("Initiating connection to '{0}:{1}'.", host, port));
|
|
|
|
|
|
|
+ DiagnosticAbstraction.Log(string.Format("Initiating connection to '{0}'.", endPoint));
|
|
|
|
|
|
|
|
- var socket = SocketFactory.Create(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
|
|
|
|
|
|
+ var socket = SocketFactory.Create(SocketType.Stream, ProtocolType.Tcp);
|
|
|
try
|
|
try
|
|
|
{
|
|
{
|
|
|
- await SocketAbstraction.ConnectAsync(socket, ep, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
+ await SocketAbstraction.ConnectAsync(socket, endPoint, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
const int socketBufferSize = 2 * Session.MaximumSshPacketSize;
|
|
const int socketBufferSize = 2 * Session.MaximumSshPacketSize;
|
|
|
socket.SendBufferSize = socketBufferSize;
|
|
socket.SendBufferSize = socketBufferSize;
|