-
-
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?
Feature/change window size request for ssh client #1062
Conversation
… window-change:WindowChangeRequestInfo
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.
Can you also contribute a small self-contained application that excercises this new method?
That application should signal an error if that method was not called exactly as expected (eg. if rows and columns where switched in our implementation).
I'd also like to discuss the name of this method. Are there better alternatives (eg. ChangeWindow)?
/// <returns>true when change is successful, or false when channel is NOT open or the request </returns> | ||
public bool WindowChangeRequest(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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
This method is essentially a wrapper for SendWindowChangeRequest
which returns a boolean. It makes sense that this method also returns boolean. Nothing will break if the request fails, so therefore it is not exceptional that the method fails.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, ChangeWindow
might be a better name. Happy to do this. Should I proceed?
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.
Ok changed in commit [61d5324]
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.
With regards to an example application - I have a fully worked example in branch glenkleidon:feature/add_vs_2022_solution
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the blocker is the failed test case on #1024
src/Renci.SshNet/ShellStream.cs
Outdated
/// <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 WindowChangeRequest(uint columns, uint rows, uint width, uint height ) |
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.
Given the rationale below, we could consider having this method return void.
I prefer to discuss this with other team members before we decide how to proceed with this.
Please remove the extra whitespace before the closing parenthesis.
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.
ok removed white space. commit [ec60725]
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.
Should return false as it is not necessary to throw an exception in this case is often of no consequence that the method does not succeed. Also it is a wrapper for the underlying method which returns boolean.
{ | ||
var shellStream = CreateShellStream(); | ||
_channelSessionMock.Setup(s => s.IsOpen).Returns(true); | ||
_channelSessionMock.Setup(s => s.SendWindowChangeRequest( |
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.
_channelSessionMock.Setup(s => s.SendWindowChangeRequest( | ||
It.IsAny<uint>(), It.IsAny<uint>(), | ||
It.IsAny<uint>(), It.IsAny<uint>())).Returns(true); | ||
Assert.IsTrue(shellStream.WindowChangeRequest(80, 25, 0, 0)); |
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.
Please also verify that SendWindowChangeRequest(...)
was actually invoked (once).
Would you mind resolving the conflicts? @glenkleidon |
I can Scott. I am busy today but it has been quite a few months since I worked on it, so I’ll need to get myself back up to speed on it.
In the next week or so.
Glen.
From: Scott Xu ***@***.***>
Sent: Tuesday, February 13, 2024 1:08 PM
To: sshnet/SSH.NET ***@***.***>
Cc: Glen Kleidon ***@***.***>; Mention ***@***.***>
Subject: Re: [sshnet/SSH.NET] Feature/change window size request for ssh client (PR #1062)
Would you mind resolving the conflicts? @glenkleidon<https://github.com/glenkleidon>
—
Reply to this email directly, view it on GitHub<#1062 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AE6JMP2P7TKISELNZQOGV5LYTLDIFAVCNFSM6AAAAAAS2XYF66VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBQGIZTINRZGE>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>
|
Tagging #40 so it is tracked there as well. |
Implemented ShellStream.WindowChangeRequest by surfacing existing implementation in (private) _channel::IChannelSession.