Table of Contents

Property ConfigureSocket

Namespace
SshSharp
Assembly
SshSharp.dll

ConfigureSocket

Sets socket options on the TCP connection to the server: TCP keep-alive, buffer sizes, the type of service (DSCP), and so on. It is called with the new socket before it connects (after it is bound to LocalEndPoint, if set), so options that must be set before the handshake, such as the receive buffer size that TCP window scaling depends on, take effect. Null (the default) leaves the system's defaults; SshSharp itself turns Nagle's algorithm off (NoDelay).

public Action<Socket>? ConfigureSocket { get; init; }

Property Value

Action<Socket>

Remarks

Used by ConnectAsync(string, int, SshClientOptions, CancellationToken) only, for a direct connection: with JumpHosts, that is the connection to the first hop (whose own options' ConfigureSocket is not used). It is not called when the connection goes through a Proxy, nor over a stream you opened yourself (ConnectAsync(Stream, SshClientOptions, bool, CancellationToken)), where the socket, if there is one, is yours to configure.

It is called once for each socket SshSharp creates, and each address of the server that is tried gets a socket of its own: once per attempt for an IP address or a name with one address, and again for each further address tried when a name has several and the first cannot be reached (or, with StaggeredConnectDelay, has not connected in time: several sockets may then be connecting at once, and those that lose are closed). Each retry that ConnectionAttempts makes creates new sockets too. The socket's family is the address's (IPv4 or IPv6, not dual-mode). It runs on the connecting thread and should only set options. An exception it throws ends the attempt and is thrown from ConnectAsync as it is.