Skip to content

Commit ef93c30

Browse files
committed
Small socket, power mode changes
- 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.
1 parent 47b803e commit ef93c30

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

WinNUT_V2/WinNUT-Client/WinNUT.vb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,19 @@ Public Class WinNUT
330330
Private Sub SystemEvents_PowerModeChanged(sender As Object, e As Microsoft.Win32.PowerModeChangedEventArgs)
331331
LogFile.LogTracing("PowerModeChangedEvent: " & [Enum].GetName(GetType(Microsoft.Win32.PowerModes), e.Mode), LogLvl.LOG_NOTICE, Me)
332332
Select Case e.Mode
333+
' Note: Windows does not wait for applications to handle a Suspend event.
333334
Case Microsoft.Win32.PowerModes.Suspend
334335
LogFile.LogTracing("Suspending WinNUT operations...", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_MAIN_GOTOSLEEP))
335336
UPSDisconnect()
336337
Case Microsoft.Win32.PowerModes.Resume
338+
If UPS_Device IsNot Nothing AndAlso UPS_Device.IsConnected Then
339+
LogFile.LogTracing("Trying to disconnect connected UPS after system resume...", LogLvl.LOG_NOTICE, Me)
340+
UPSDisconnect()
341+
End If
337342
If My.Settings.NUT_AutoReconnect Then
338-
LogFile.LogTracing("Reconnecting after system resume.", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_MAIN_EXITSLEEP))
339-
UPS_Connect(True)
340-
End If
343+
LogFile.LogTracing("Reconnecting after system resume.", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_MAIN_EXITSLEEP))
344+
UPS_Connect(True)
345+
End If
341346
End Select
342347
End Sub
343348

WinNUT_V2/WinNUT-Client_Common/Nut_Socket.vb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,14 @@ Public Class Nut_Socket
161161
''' <summary>
162162
''' Perform various functions necessary to disconnect the socket from the NUT server.
163163
''' </summary>
164-
''' <param name="Forceful">Skip sending the LOGOUT command to the NUT server. Unknown effects.</param>
164+
''' <param name="forceful">Skip sending the LOGOUT command to the NUT server. Unknown effects.</param>
165165
Public Sub Disconnect(Optional forceful = False)
166166
If Not forceful AndAlso IsConnected AndAlso IsLoggedIn Then
167-
Try
168-
Query_Data("LOGOUT")
169-
Finally
170-
Close_Socket()
171-
RaiseEvent SocketDisconnected()
172-
End Try
167+
Query_Data("LOGOUT")
173168
End If
169+
170+
Close_Socket()
171+
RaiseEvent SocketDisconnected()
174172
End Sub
175173

176174
''' <summary>

0 commit comments

Comments
 (0)