Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ dotnet_diagnostic.S2971.severity = none
# This is rather harmless.
dotnet_diagnostic.S3218.severity = none

# S3236: Remove this argument from the method call; it hides the caller information.
dotnet_diagnostic.S3236.severity = none

# S3267: Loops should be simplified with "LINQ" expressions
# https://rules.sonarsource.com/csharp/RSPEC-3267
#
Expand Down
12 changes: 6 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ for:

build_script:
- echo build
- dotnet build -f net8.0 -c Debug test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
- dotnet build -f net8.0 -c Debug test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj
- dotnet build -f net9.0 -c Debug test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
- dotnet build -f net9.0 -c Debug test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj
- dotnet build -f net48 -c Debug test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj

test_script:
- sh: echo "Run unit tests"
- sh: dotnet test -f net8.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_unit_test_net_8_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_unit_test_net_8_coverage.xml test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
- sh: dotnet test -f net9.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_unit_test_net_9_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_unit_test_net_9_coverage.xml test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
- sh: echo "Run integration tests"
- sh: dotnet test -f net8.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_integration_test_net_8_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_integration_test_net_8_coverage.xml test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj
- sh: dotnet test -f net9.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=linux_integration_test_net_9_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/linux_integration_test_net_9_coverage.xml test/Renci.SshNet.IntegrationTests/Renci.SshNet.IntegrationTests.csproj
# Also run a subset of the integration tests targeting netfx using mono. This is a temporary measure to get
# some coverage until a proper solution for running the .NET Framework integration tests in CI is found.
# Running all the tests causes problems which are not worth solving in this rare configuration.
Expand All @@ -52,8 +52,8 @@ for:
- dotnet pack -c Release

test_script:
- ps: echo "Run unit tests for .NET 8.0"
- ps: dotnet test -f net8.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=windows_unit_test_net_8_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/windows_unit_test_net_8_coverage.xml test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
- ps: echo "Run unit tests for .NET 9.0"
- ps: dotnet test -f net9.0 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=windows_unit_test_net_9_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/windows_unit_test_net_9_coverage.xml test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
- ps: echo "Run unit tests for .NET Framework 4.6.2"
- ps: dotnet test -f net462 -c Debug --no-restore --no-build --results-directory artifacts --logger Appveyor --logger "console;verbosity=normal" --logger "liquid.md;LogFileName=windows_unit_test_net_4_6_2_report.md" -p:CollectCoverage=true -p:CoverletOutputFormat=cobertura -p:CoverletOutput=../../artifacts/windows_unit_test_net_4_6_2_coverage.xml test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj

Expand Down
4 changes: 2 additions & 2 deletions src/Renci.SshNet/Channels/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Renci.SshNet.Channels
/// </summary>
internal abstract class Channel : IChannel
{
private readonly object _serverWindowSizeLock = new object();
private readonly object _messagingLock = new object();
private readonly Lock _serverWindowSizeLock = new Lock();
private readonly Lock _messagingLock = new Lock();
private readonly uint _initialWindowSize;
private readonly ISession _session;
private EventWaitHandle _channelClosedWaitHandle = new ManualResetEvent(initialState: false);
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Channels/ChannelDirectTcpip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Renci.SshNet.Channels
/// </summary>
internal sealed class ChannelDirectTcpip : ClientChannel, IChannelDirectTcpip
{
private readonly object _socketLock = new object();
private readonly Lock _socketLock = new Lock();

private EventWaitHandle _channelOpen = new AutoResetEvent(initialState: false);
private EventWaitHandle _channelData = new AutoResetEvent(initialState: false);
Expand Down
5 changes: 4 additions & 1 deletion src/Renci.SshNet/Channels/ChannelForwardedTcpip.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Net;
using System.Net.Sockets;
#if NET9_0_OR_GREATER
using System.Threading;
#endif

using Renci.SshNet.Abstractions;
using Renci.SshNet.Common;
Expand All @@ -13,7 +16,7 @@ namespace Renci.SshNet.Channels
/// </summary>
internal sealed class ChannelForwardedTcpip : ServerChannel, IChannelForwardedTcpip
{
private readonly object _socketShutdownAndCloseLock = new object();
private readonly Lock _socketShutdownAndCloseLock = new Lock();
private Socket _socket;
private IForwardedPort _forwardedPort;

Expand Down
19 changes: 19 additions & 0 deletions src/Renci.SshNet/Common/Lock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#if !NET9_0_OR_GREATER
using System.Threading;

namespace Renci.SshNet.Common
{
internal sealed class Lock
{
public bool TryEnter()
{
return Monitor.TryEnter(this);
}

public void Exit()
{
Monitor.Exit(this);
}
}
}
#endif
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Renci.SshNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyName>Renci.SshNet</AssemblyName>
<Product>SSH.NET</Product>
<AssemblyTitle>SSH.NET</AssemblyTitle>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Renci.SshNet/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class Session : ISession
/// Holds an object that is used to ensure only a single thread can read from
/// <see cref="_socket"/> at any given time.
/// </summary>
private readonly object _socketReadLock = new object();
private readonly Lock _socketReadLock = new Lock();

/// <summary>
/// Holds an object that is used to ensure only a single thread can write to
Expand All @@ -90,7 +90,7 @@ public class Session : ISession
/// This is also used to ensure that <see cref="_outboundPacketSequence"/> is
/// incremented atomatically.
/// </remarks>
private readonly object _socketWriteLock = new object();
private readonly Lock _socketWriteLock = new Lock();

/// <summary>
/// Holds an object that is used to ensure only a single thread can dispose
Expand Down Expand Up @@ -1911,7 +1911,7 @@ private bool IsSocketConnected()
return false;
}

if (!Monitor.TryEnter(_socketReadLock))
if (!_socketReadLock.TryEnter())
{
return true;
}
Expand All @@ -1923,7 +1923,7 @@ private bool IsSocketConnected()
}
finally
{
Monitor.Exit(_socketReadLock);
_socketReadLock.Exit();
}
}
finally
Expand Down
2 changes: 1 addition & 1 deletion src/Renci.SshNet/Sftp/SftpFileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Renci.SshNet.Sftp
#pragma warning restore IDE0079
public class SftpFileStream : Stream
{
private readonly object _lock = new object();
private readonly Lock _lock = new Lock();
private readonly int _readBufferSize;
private readonly int _writeBufferSize;

Expand Down
5 changes: 4 additions & 1 deletion src/Renci.SshNet/SshMessageFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Globalization;
#if NET9_0_OR_GREATER
using System.Threading;
#endif

using Renci.SshNet.Common;
using Renci.SshNet.Messages;
Expand All @@ -14,7 +17,7 @@ internal sealed class SshMessageFactory
{
private readonly MessageMetadata[] _enabledMessagesByNumber;
private readonly bool[] _activatedMessagesById;
private readonly object _lock = new object();
private readonly Lock _lock = new Lock();

internal static readonly MessageMetadata[] AllMessages = new MessageMetadata[]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<PublishAot>true</PublishAot>
<SelfContained>true</SelfContained>
<TrimmerSingleWarn>false</TrimmerSingleWarn>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net48;net8.0</TargetFrameworks>
<TargetFrameworks>net48;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);SYSLIB0021;SYSLIB1045;SYSLIB0014;IDE0220;IDE0010</NoWarn>
Expand Down
6 changes: 4 additions & 2 deletions test/Renci.SshNet.Tests/Common/AsyncSocketListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Net;
using System.Net.Sockets;
using System.Threading;

using Renci.SshNet.Common;
#pragma warning restore IDE0005

namespace Renci.SshNet.Tests.Common
Expand All @@ -13,7 +15,7 @@ public class AsyncSocketListener : IDisposable
private readonly IPEndPoint _endPoint;
private readonly ManualResetEvent _acceptCallbackDone;
private readonly List<Socket> _connectedClients;
private readonly object _syncLock;
private readonly Lock _syncLock;
private Socket _listener;
private Thread _receiveThread;
private bool _started;
Expand All @@ -31,7 +33,7 @@ public AsyncSocketListener(IPEndPoint endPoint)
_endPoint = endPoint;
_acceptCallbackDone = new ManualResetEvent(false);
_connectedClients = new List<Socket>();
_syncLock = new object();
_syncLock = new Lock();
ShutdownRemoteCommunicationSocket = true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/Renci.SshNet.Tests/Renci.SshNet.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net462;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down