Files
Rob Hague fd05d76ad6 Use ArraySegment for channel data (#1650)
The library currently allocates 4 bytes (and some) for every 1 byte of file
downloaded(*). It could be 0. This takes it to 3.

(*)
1. Array allocated for read of encrypted packet from socket
2. Array for decrypted packet
3. Array for channel data (removed in this change)
4. Array for sftp data packet
2025-06-06 08:52:23 +02:00

51 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading;
using Renci.SshNet.Common;
namespace Renci.SshNet.Tests.Classes
{
internal class SubsystemSessionStub : SubsystemSession
{
private int _onChannelOpenInvocationCount;
public SubsystemSessionStub(ISession session, string subsystemName, int operationTimeout)
: base(session, subsystemName, operationTimeout)
{
OnDataReceivedInvocations = new List<ChannelDataEventArgs>();
}
public int OnChannelOpenInvocationCount
{
get { return _onChannelOpenInvocationCount; }
}
public IList<ChannelDataEventArgs> OnDataReceivedInvocations { get; private set; }
public Exception OnChannelOpenException { get; set; }
public Exception OnDataReceivedException { get; set; }
protected override void OnChannelOpen()
{
_ = Interlocked.Increment(ref _onChannelOpenInvocationCount);
if (OnChannelOpenException != null)
{
throw OnChannelOpenException;
}
}
protected override void OnDataReceived(ArraySegment<byte> data)
{
OnDataReceivedInvocations.Add(new ChannelDataEventArgs(0, data));
if (OnDataReceivedException != null)
{
throw OnDataReceivedException;
}
}
}
}