Improve shell stream
Improve ShellStream
-
Added SendWindowChangeRequest to ShellStream
-
Added a new constructor to ShellStream
-
SshClient adds an overload function for CreateShellStream
When creating ShellStream, the channel will be immediately opened in the constructor of ShellStream. At this time, the calling module may not have subscribed to ShellStream's DataReceived event, which may result in the loss of a small piece of data immediately after connection. You can use ShellStream's new constructor to solve this problem
Why does AppVeyor fail?
Hi @294797392
Are you able solve your problem using the Read method instead of the DataReceived event? e.g.
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = shellStream.Read(buffer) != 0)
{
// Process "bytesRead" bytes from buffer
}
Yes, using the Read function can solve my problem. But I think it's best to optimize it, as other developers may also encounter this issue when using it. Do you think it is necessary to add the SendWindowChangeRequest function? @Rob-Hague
Yes it seems reasonable to add SendWindowChangeRequest - there have been previous requests for it. Personally I would suggest to:
- make it return
void: the server does not respond to a window-change request, and our implementation inChannelSessionjust returns true so it is not much use to returnbool - add
ThrowHelper.ThrowObjectDisposedIf(_disposed, this);at the start of the method - add at least a basic test. For example, in
test\Renci.SshNet.Tests\Classes\ShellStreamTest.csthere could be a test which verifies the call toIChannelSessionmock, and verifies theObjectDisposedExceptionwhen the ShellStream is closed
Let me know what you think
I agree with your idea. I tried to modify the code and added the SendWindowChangeRequest method, but found that if it returns void, IDE0058 compilation error will occur. If void is returned, there may be many modifications and it will also affect the consistency of the code (there are many methods in ChannelSession that directly return true). Perhaps having a return value would be better than having no return value, as a return value can prompt the caller about the execution result of the method you called, and in the future we can also add more error handling to the method (if necessary)! And I believe that when developing the ChannelSession module initially, there must have been a reason for returning a boolean. @Rob-Hague
Ok, bool seems fine to me - I don't feel strongly about it
Ok, bool seems fine to me - I don't feel strongly about it
Do you agree with me changing it to a boolean return value? If you agree, I will submit another PR
Yes