Skip to content

PipeStream returns 0 instead of blocking when running a command with… #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions src/Renci.SshNet/Common/PipeStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,22 @@ public override int Read(byte[] buffer, int offset, int count)
/// <returns><c>True</c> if data available; otherwise<c>false</c>.</returns>
private bool ReadAvailable(int count)
{
if (Length == 0 && !IsEndOfStream())
{
return false;
}

return (Length >= count || _isFlushed) &&
(Length >= (count + 1) || !BlockLastReadBuffer);
}

public Func<bool> EndOfStream { private get; set; }

private bool IsEndOfStream()
{
return (EndOfStream == null) ? Length == 0 : EndOfStream();
}

///<summary>
///When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
///</summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Renci.SshNet/SshCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ public IAsyncResult BeginExecute(AsyncCallback callback, object state)

// Initialize output streams
OutputStream = new PipeStream();
((PipeStream)OutputStream).EndOfStream = () => { return _asyncResult.IsCompleted; };
ExtendedOutputStream = new PipeStream();
((PipeStream)ExtendedOutputStream).EndOfStream = () => { return _asyncResult.IsCompleted; };

_result = null;
_error = null;
Expand Down