-
-
Notifications
You must be signed in to change notification settings - Fork 940
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
Feature/change window size request for ssh client #1062
base: develop
Are you sure you want to change the base?
Changes from all commits
6452fda
485adff
a5d7b01
ec60725
f77df6a
61d5324
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
using System.Threading; | ||
using System.Text.RegularExpressions; | ||
using Renci.SshNet.Abstractions; | ||
using System.CodeDom; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Renci.SshNet | ||
{ | ||
|
@@ -52,6 +54,19 @@ public bool DataAvailable | |
} | ||
} | ||
} | ||
/// <summary> | ||
/// Sends a Window Change Request via the Channel. | ||
/// </summary> | ||
/// <param name="columns">New screen width in # of columns</param> | ||
/// <param name="rows">New screen height in # of rows</param> | ||
/// <param name="width">New screen width in Pixels</param> | ||
/// <param name="height">New screen height in Pixels</param> | ||
/// <returns>true when change is successful, or false when channel is NOT open or the request </returns> | ||
public bool ChangeWindow(uint columns, uint rows, uint width, uint height ) | ||
{ | ||
if (_channel==null || !_channel.IsOpen) return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please have it throw an ObjectDisposedException when _channel is null, and an InvalidOperationException if the channel is closed. Please document this as such and add corresponding unit tests. I would've prefered to have the method on ChannelSession also throw if the channel were closed, but that would be considered a breaking change. That method currently either throws or returns true, never false. It also returns true if the channel is closed 😌 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is essentially a wrapper for I always ask myself - as library developers, can we KNOW that it is Exceptional that a method is called when in the wrong state or is it simply unexpected. Often the answer is that you can't know the answer because we don't know the context of how the method is being used. The developer using the library will know if the situation is exceptional and can throw if it is. All we need to do is say whether or not it succeeded. If you throw an exception in a library - it has to be fundamentally wrong to do so. In this case, I don't think it is - it is merely unexpected and of no consequence. There wont be any data coming back to be "in the wrong shape" so it wont matter that the method failed. There might be an argument for Throwing the exception if the channel had never been opened, but as this happens in the constructor that is not possible. The scenario that comes to mind is, in the CanClose Event of a Desktop App, OR the Close browser event, the shape of the window may change during clean up. If that happens, the event to change window shape MAY still be attached causing the event to fire when the channel has already closed. It is much simpler to handle for the developer if the method does not throw an exception and the unexpected event can be ignored. With an exception, in order to properly clean up, the developer must remember to unsubscribe to events or risk an exception being raised when it is of no consequence. Returning false allows to the developer to decide if failed call to change window size is exceptional. So I think returning a boolean is the right call here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok changed in commit [61d5324] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With regards to an example application - I have a fully worked example in branch Should consider doing a pull request on that one but I need some help with a failed test case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually the blocker is the failed test case on #1024 |
||
return _channel.SendWindowChangeRequest(columns, rows, width, height); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the number of bytes that will be written to the internal buffer. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very useful since
SendWindowChangeRequest(...)
always returns true, but let's discuss.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I dont think SendWindowChangeRequest SHOULD always be true. For example a change to size of 0,0,0,0 should fail and probably will on some pty implementations.