Skip to content

Commit 094cc8d

Browse files
SSH 2025.0.1 EM Edition
1 parent b199467 commit 094cc8d

12 files changed

Lines changed: 181 additions & 88 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,4 @@ build/target/
489489
# Docs
490490
docfx/_site/
491491
docfx/api/
492+
/src/EMsshnet.snk

src/Renci.SshNet/.editorconfig

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,5 @@ dotnet_diagnostic.MA0040.severity = none
192192
# duplicate of CA1849
193193
dotnet_diagnostic.MA0042.severity = none
194194

195-
# S3236: Caller information arguments should not be provided explicitly
196-
dotnet_diagnostic.S3236.severity = none
197-
198-
# S3358: Ternary operators should not be nested
199-
dotnet_diagnostic.S3358.severity = none
195+
# Default severity for analyzer diagnostics with category 'Usage'
196+
dotnet_analyzer_diagnostic.category-Usage.severity = none

src/Renci.SshNet/Abstractions/SocketAbstraction.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public static void ReadContinuous(Socket socket, byte[] buffer, int offset, int
204204
public static int ReadByte(Socket socket, TimeSpan timeout)
205205
{
206206
var buffer = new byte[1];
207-
if (Read(socket, buffer, 0, 1, timeout) == 0)
207+
if (Read(socket, buffer, 0, 1, timeout, out _) == 0)
208208
{
209209
return -1;
210210
}
@@ -243,7 +243,7 @@ public static void SendByte(Socket socket, byte value)
243243
public static byte[] Read(Socket socket, int size, TimeSpan timeout)
244244
{
245245
var buffer = new byte[size];
246-
_ = Read(socket, buffer, 0, size, timeout);
246+
_ = Read(socket, buffer, 0, size, timeout, out _);
247247
return buffer;
248248
}
249249

@@ -255,32 +255,34 @@ public static byte[] Read(Socket socket, int size, TimeSpan timeout)
255255
/// <param name="offset">The position in <paramref name="buffer"/> parameter to store the received data.</param>
256256
/// <param name="size">The number of bytes to receive.</param>
257257
/// <param name="readTimeout">The maximum time to wait until <paramref name="size"/> bytes have been received.</param>
258+
/// <param name="lastSocketError">Last socket error.</param>
258259
/// <returns>
259260
/// The number of bytes received.
260261
/// </returns>
261262
/// <remarks>
262263
/// <para>
263-
/// If no data is available for reading, the <see cref="Read(Socket, byte[], int, int, TimeSpan)"/> method will
264+
/// If no data is available for reading, the <see cref="Read(Socket, byte[], int, int, TimeSpan, out SocketError)"/> method will
264265
/// block until data is available or the time-out value is exceeded. If the time-out value is exceeded, the
265-
/// <see cref="Read(Socket, byte[], int, int, TimeSpan)"/> call will throw a <see cref="SshOperationTimeoutException"/>.
266+
/// <see cref="Read(Socket, byte[], int, int, TimeSpan, out SocketError)"/> call will throw a <see cref="SshOperationTimeoutException"/>.
266267
/// </para>
267268
/// <para>
268269
/// If you are in non-blocking mode, and there is no data available in the in the protocol stack buffer, the
269-
/// <see cref="Read(Socket, byte[], int, int, TimeSpan)"/> method will complete immediately and throw a <see cref="SocketException"/>.
270+
/// <see cref="Read(Socket, byte[], int, int, TimeSpan, out SocketError)"/> method will complete immediately and throw a <see cref="SocketException"/>.
270271
/// </para>
271272
/// </remarks>
272-
public static int Read(Socket socket, byte[] buffer, int offset, int size, TimeSpan readTimeout)
273+
public static int Read(Socket socket, byte[] buffer, int offset, int size, TimeSpan readTimeout, out SocketError lastSocketError)
273274
{
274275
var totalBytesRead = 0;
275276
var totalBytesToRead = size;
276277

277-
socket.ReceiveTimeout = readTimeout.AsTimeout();
278+
socket.ReceiveTimeout = readTimeout.AsTimeout(nameof(readTimeout));
279+
lastSocketError = SocketError.SocketError;
278280

279281
do
280282
{
281283
try
282284
{
283-
var bytesRead = socket.Receive(buffer, offset + totalBytesRead, totalBytesToRead - totalBytesRead, SocketFlags.None);
285+
var bytesRead = socket.Receive(buffer, offset + totalBytesRead, totalBytesToRead - totalBytesRead, SocketFlags.None, out lastSocketError);
284286
if (bytesRead == 0)
285287
{
286288
return 0;
@@ -332,10 +334,10 @@ public static void Send(Socket socket, byte[] data, int offset, int size)
332334
{
333335
try
334336
{
335-
var bytesSent = socket.Send(data, offset + totalBytesSent, totalBytesToSend - totalBytesSent, SocketFlags.None);
336-
if (bytesSent == 0)
337+
var bytesSent = socket.Send(data, offset + totalBytesSent, totalBytesToSend - totalBytesSent, SocketFlags.None, out var errorCode);
338+
if (bytesSent == 0 && errorCode != SocketError.Success)
337339
{
338-
throw new SshConnectionException("An established connection was aborted by the server.",
340+
throw new SshConnectionException(string.Format("An established connection was aborted by the server. (socket error: {0})", errorCode),
339341
DisconnectReason.ConnectionLost);
340342
}
341343

src/Renci.SshNet/Connection/ConnectorBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ protected static int SocketRead(Socket socket, byte[] buffer, int offset, int le
136136
/// <exception cref="SocketException">The read failed.</exception>
137137
protected static int SocketRead(Socket socket, byte[] buffer, int offset, int length, TimeSpan readTimeout)
138138
{
139-
var bytesRead = SocketAbstraction.Read(socket, buffer, offset, length, readTimeout);
139+
var bytesRead = SocketAbstraction.Read(socket, buffer, offset, length, readTimeout, out var lastSocketError);
140140
if (bytesRead == 0)
141141
{
142-
throw new SshConnectionException("An established connection was aborted by the server.",
142+
throw new SshConnectionException(string.Format("An established connection was aborted by the server. (socket error: {0})", lastSocketError),
143143
DisconnectReason.ConnectionLost);
144144
}
145145

src/Renci.SshNet/Connection/HttpConnector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private static string SocketReadLine(Socket socket, TimeSpan readTimeout)
154154
// to be processed by subsequent invocations
155155
do
156156
{
157-
var bytesRead = SocketAbstraction.Read(socket, data, 0, data.Length, readTimeout);
157+
var bytesRead = SocketAbstraction.Read(socket, data, 0, data.Length, readTimeout, out _);
158158
if (bytesRead == 0)
159159
{
160160
// the remote server shut down the socket

src/Renci.SshNet/Connection/ProtocolVersionExchange.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private static string SocketReadLine(Socket socket, TimeSpan timeout, List<byte>
154154
// to be processed by subsequent invocations.
155155
while (true)
156156
{
157-
var bytesRead = SocketAbstraction.Read(socket, data, 0, data.Length, timeout);
157+
var bytesRead = SocketAbstraction.Read(socket, data, 0, data.Length, timeout, out _);
158158
if (bytesRead == 0)
159159
{
160160
// The remote server shut down the socket.

src/Renci.SshNet/ForwardedPortDynamic.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ private bool HandleSocks4(Socket socket, IChannelDirectTcpip channel, TimeSpan t
476476
}
477477

478478
var portBuffer = new byte[2];
479-
if (SocketAbstraction.Read(socket, portBuffer, 0, portBuffer.Length, timeout) == 0)
479+
if (SocketAbstraction.Read(socket, portBuffer, 0, portBuffer.Length, timeout, out _) == 0)
480480
{
481481
// SOCKS client closed connection
482482
return false;
@@ -485,7 +485,7 @@ private bool HandleSocks4(Socket socket, IChannelDirectTcpip channel, TimeSpan t
485485
var port = BinaryPrimitives.ReadUInt16BigEndian(portBuffer);
486486

487487
var ipBuffer = new byte[4];
488-
if (SocketAbstraction.Read(socket, ipBuffer, 0, ipBuffer.Length, timeout) == 0)
488+
if (SocketAbstraction.Read(socket, ipBuffer, 0, ipBuffer.Length, timeout, out _) == 0)
489489
{
490490
// SOCKS client closed connection
491491
return false;
@@ -531,7 +531,7 @@ private bool HandleSocks5(Socket socket, IChannelDirectTcpip channel, TimeSpan t
531531
}
532532

533533
var authenticationMethods = new byte[authenticationMethodsCount];
534-
if (SocketAbstraction.Read(socket, authenticationMethods, 0, authenticationMethods.Length, timeout) == 0)
534+
if (SocketAbstraction.Read(socket, authenticationMethods, 0, authenticationMethods.Length, timeout, out _) == 0)
535535
{
536536
// SOCKS client closed connection
537537
return false;
@@ -599,7 +599,7 @@ private bool HandleSocks5(Socket socket, IChannelDirectTcpip channel, TimeSpan t
599599
}
600600

601601
var portBuffer = new byte[2];
602-
if (SocketAbstraction.Read(socket, portBuffer, 0, portBuffer.Length, timeout) == 0)
602+
if (SocketAbstraction.Read(socket, portBuffer, 0, portBuffer.Length, timeout, out _) == 0)
603603
{
604604
// SOCKS client closed connection
605605
return false;
@@ -625,7 +625,7 @@ private static string GetSocks5Host(int addressType, Socket socket, TimeSpan tim
625625
case 0x01: // IPv4
626626
{
627627
var addressBuffer = new byte[4];
628-
if (SocketAbstraction.Read(socket, addressBuffer, 0, 4, timeout) == 0)
628+
if (SocketAbstraction.Read(socket, addressBuffer, 0, 4, timeout, out _) == 0)
629629
{
630630
// SOCKS client closed connection
631631
return null;
@@ -645,7 +645,7 @@ private static string GetSocks5Host(int addressType, Socket socket, TimeSpan tim
645645
}
646646

647647
var addressBuffer = new byte[length];
648-
if (SocketAbstraction.Read(socket, addressBuffer, 0, addressBuffer.Length, timeout) == 0)
648+
if (SocketAbstraction.Read(socket, addressBuffer, 0, addressBuffer.Length, timeout, out _) == 0)
649649
{
650650
// SOCKS client closed connection
651651
return null;
@@ -658,7 +658,7 @@ private static string GetSocks5Host(int addressType, Socket socket, TimeSpan tim
658658
case 0x04: // IPv6
659659
{
660660
var addressBuffer = new byte[16];
661-
if (SocketAbstraction.Read(socket, addressBuffer, 0, 16, timeout) == 0)
661+
if (SocketAbstraction.Read(socket, addressBuffer, 0, 16, timeout, out _) == 0)
662662
{
663663
// SOCKS client closed connection
664664
return null;
@@ -728,7 +728,7 @@ private static string ReadString(Socket socket, TimeSpan timeout)
728728

729729
while (true)
730730
{
731-
if (SocketAbstraction.Read(socket, buffer, 0, 1, timeout) == 0)
731+
if (SocketAbstraction.Read(socket, buffer, 0, 1, timeout, out _) == 0)
732732
{
733733
// SOCKS client closed connection
734734
return null;

src/Renci.SshNet/Renci.SshNet.csproj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<AssemblyName>Renci.SshNet</AssemblyName>
5-
<Product>SSH.NET</Product>
6-
<AssemblyTitle>SSH.NET</AssemblyTitle>
7-
<TargetFrameworks>net462;netstandard2.0;net8.0;net9.0</TargetFrameworks>
4+
<AssemblyName>EasyMorph.SshNet</AssemblyName>
5+
<LangVersion>12</LangVersion>
6+
<SignAssembly>false</SignAssembly>
7+
<TargetFrameworks>net462;net8.0</TargetFrameworks>
88
</PropertyGroup>
99

1010
<PropertyGroup>
1111
<IsPackable>true</IsPackable>
12-
<PackageId>SSH.NET</PackageId>
12+
<PackageId>EasyMorph.SshNet</PackageId>
1313
<Title>SSH.NET</Title>
1414
<Description>SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.</Description>
1515
<Copyright>Copyright © Renci 2010-$([System.DateTime]::UtcNow.Year)</Copyright>
@@ -23,6 +23,10 @@
2323
<NBGV_ThisAssemblyIncludesPackageVersion>true</NBGV_ThisAssemblyIncludesPackageVersion>
2424
<EmbedUntrackedSources>true</EmbedUntrackedSources>
2525
<PublishRepositoryUrl>true</PublishRepositoryUrl>
26+
<RunAnalyzersDuringBuild>False</RunAnalyzersDuringBuild>
27+
<RunAnalyzersDuringLiveAnalysis>False</RunAnalyzersDuringLiveAnalysis>
28+
<EnforceCodeStyleInBuild>False</EnforceCodeStyleInBuild>
29+
<EnableNETAnalyzers>False</EnableNETAnalyzers>
2630
</PropertyGroup>
2731

2832
<Target Name="SetVersionProperties" BeforeTargets="Build" DependsOnTargets="GetBuildVersion">

0 commit comments

Comments
 (0)