-
Notifications
You must be signed in to change notification settings - Fork 21
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
Resuming from Sleep and other connection fixes #163
Conversation
We previously didn't support the Suspend power mode change, which meant WinNUT would be paused in the middle of execution (and with an open socket) if the system goes to sleep. Now WinNUT has the chance to close down operations and connections, which seems to at least help with errors while changing power states. It looks like WinNUT still tries to reconnect too quickly after the system resumes from sleep (before networking is fully restored?) In the interest of reducing notification spam, it may be best to have WinNUT wait a few seconds before reconnecting.
Variable was essentially unused except for within the Update GUI trigger function, when it's predetermined anyways.
- Socket Disconnect method now calls the Close_Socket method and raises the SocketDisconnected event in more cases - System Resume event now tries to disconnect the UPS if it's still considered connected.
Nut_Socket.vb - Removed Socket object and any relating code since TcpClient is already providing the functionality. - Remove Disconnected event since this will be provided through exceptions or intentional commands. - Fixed use of LOGIN protocol command - Simplify Disconnect method UPS_Device.vb - Created dedicated Login method that interfaces with the socket layer. WinNUT.vb - Calls Login method only when a username is provided. Fixes forced/unintended logins.
Nut_Socket.vb - ConnectionStatus property checks for null client object before checking .Connected property - TcpClient object is left null at construction, and only instantiated during a Connection subroutine. - Disconnect subroutine doesn't explicitly check for connection status on the TcpClient object before running anymore. This allows it to dispose/close all objects regardless. UPS_Device.vb - Fixed polling interval not being applied to timer. Associated property is now read only, and the interval is set directly on the timer during construction. - Fixed missing call to socket's Disconnect subroutine, and added a general exception catch-all. - Removed Login code from Reconnect subroutine, leaving that to external code. - Removed ReConnected event since it seems to duplicate the Connected event's calls. WinNUT.vb - Moved Login call to connection finalization subroutine. - Added LogException call during protocol error handling.
i am happy to see this PR--i previously have been using a fork of this repo I made for myself which the only change being the related to #65, i believe it makes sense for this PR to also address a configurable option for the considering this software is otherwise perfect for me besides the connection issue, it would be greatly appreciated and thank you for all your work on this! |
Hi @kirsch33, thanks for your interest and sorry you had to fork just for that small change! 😄 To be honest, I wasn't planning on tackling #65 here since I'm helping another user who's experiencing a multitude of issues at the moment. Generally though, I think I'm leaning more towards indefinite/persistent connections instead of a set amount before giving up - let me know in #65 if you think it should be different. |
@gbakeman that sounds good to me! and its no issue. this app is perfect otherwise, or else I wouldnt have went thru all that trouble lol so kudos to you and the other maintainers. |
- Removed redundant IsConnected property in favor of ConnectionStatus - Renamed Nut and Net version properties and converted them to auto-implemented properties. - Wrapped version query statements in try-catch blocks in case servers that throw an error for these queries (Synology in particular) may not have further problems with other queries. - Added support for Net version 1.3
Socket
ConnectionStatus
boolean property while maintaining null checkSocket
object in favor ofTcpClient
for underlying socket managementSocketDisconnected
eventLOGIN
command syntaxUPS Device
WinNUT
UpdateMethod
property and fieldSuspend
system power mode change to try to prepare WinNUT for suspension (isn't always called before system suspends.)Resume
system power mode change to cleanup WinNUT's state if it was left connected while suspending previouslyRelated