Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update per code review
  • Loading branch information
scott-xu committed Jun 13, 2024
commit b0be78a8e1e49daa11baf150473c0ae77f837bb3
14 changes: 14 additions & 0 deletions src/Renci.SshNet/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Renci.SshNet
/// </summary>
public class Shell : IDisposable
{
private const int DefaultBufferSize = 1024;

private readonly ISession _session;
private readonly string _terminalName;
private readonly uint _columns;
Expand Down Expand Up @@ -112,6 +114,18 @@ internal Shell(ISession session, Stream input, Stream output, Stream extendedOut
/// <param name="noTerminal">Disables pseudo terminal allocation or not.</param>
private Shell(ISession session, Stream input, Stream output, Stream extendedOutput, int bufferSize, bool noTerminal)
{
if (bufferSize == -1)
{
bufferSize = DefaultBufferSize;
}
#if NET8_0_OR_GREATER
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(bufferSize);
#else
if (bufferSize <= 0)
{
throw new ArgumentOutOfRangeException(nameof(bufferSize));
}
#endif
_session = session;
_input = input;
_outputStream = output;
Expand Down
16 changes: 11 additions & 5 deletions src/Renci.SshNet/ShellStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace Renci.SshNet
/// </summary>
public class ShellStream : Stream
{
private const int DefaultBufferSize = 1024;

private readonly ISession _session;
private readonly Encoding _encoding;
private readonly IChannelSession _channel;
Expand Down Expand Up @@ -96,7 +98,7 @@ private void AssertValid()
/// <exception cref="SshException">The pseudo-terminal request was not accepted by the server.</exception>
/// <exception cref="SshException">The request to start a shell was not accepted by the server.</exception>
internal ShellStream(ISession session, string terminalName, uint columns, uint rows, uint width, uint height, IDictionary<TerminalModes, uint> terminalModeValues, int bufferSize)
: this(session, bufferSize, disablePTY: false)
: this(session, bufferSize, noTerminal: false)
{
try
{
Expand Down Expand Up @@ -127,7 +129,7 @@ internal ShellStream(ISession session, string terminalName, uint columns, uint r
/// <exception cref="SshException">The channel could not be opened.</exception>
/// <exception cref="SshException">The request to start a shell was not accepted by the server.</exception>
internal ShellStream(ISession session, int bufferSize)
: this(session, bufferSize, disablePTY: true)
: this(session, bufferSize, noTerminal: true)
{
try
{
Expand All @@ -150,10 +152,14 @@ internal ShellStream(ISession session, int bufferSize)
/// </summary>
/// <param name="session">The SSH session.</param>
/// <param name="bufferSize">The size of the buffer.</param>
/// <param name="disablePTY">Disables pseudo terminal allocation or not.</param>
/// <param name="noTerminal">Disables pseudo terminal allocation or not.</param>
/// <exception cref="SshException">The channel could not be opened.</exception>
private ShellStream(ISession session, int bufferSize, bool disablePTY)
private ShellStream(ISession session, int bufferSize, bool noTerminal)
{
if (bufferSize == -1)
{
bufferSize = DefaultBufferSize;
}
#if NET8_0_OR_GREATER
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(bufferSize);
#else
Expand All @@ -177,7 +183,7 @@ private ShellStream(ISession session, int bufferSize, bool disablePTY)
_readBuffer = new byte[bufferSize];
_writeBuffer = new byte[bufferSize];

_noTerminal = disablePTY;
_noTerminal = noTerminal;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Renci.SshNet/SshClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public Shell CreateShell(Encoding encoding, string input, Stream output, Stream
/// Returns a representation of a <see cref="Shell" /> object.
/// </returns>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
public Shell CreateShellNoTerminal(Stream input, Stream output, Stream extendedOutput, int bufferSize = 1024)
public Shell CreateShellNoTerminal(Stream input, Stream output, Stream extendedOutput, int bufferSize = -1)
{
EnsureSessionIsOpen();

Expand Down Expand Up @@ -476,7 +476,7 @@ public ShellStream CreateShellStream(string terminalName, uint columns, uint row
/// The created <see cref="ShellStream"/> instance.
/// </returns>
/// <exception cref="SshConnectionException">Client is not connected.</exception>
public ShellStream CreateShellStreamNoTerminal(int bufferSize = 1024)
public ShellStream CreateShellStreamNoTerminal(int bufferSize = -1)
{
EnsureSessionIsOpen();

Expand Down