Skip to content

Commit 0f90e43

Browse files
committed
Handle adverse connection conditions on resume
It appears that if WinNUT resumes operation from a suspended state and the computer's networking is not prepared for a connection, then WinNUT will only try reconnecting once and hard-fail without launching a reconnection timer. Connect_UPS has been modified so that it will launch the reconnection timer if required by the caller. - Reconnection interval is now 5 seconds regardless of compiler constants
1 parent dbc2d36 commit 0f90e43

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

WinNUT_V2/WinNUT-Client/WinNUT.vb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,12 @@ Public Class WinNUT
286286
Case Microsoft.Win32.PowerModes.Resume
287287
LogFile.LogTracing("Restarting WinNUT after waking up from Windows", LogLvl.LOG_NOTICE, Me, StrLog.Item(AppResxStr.STR_MAIN_EXITSLEEP))
288288
If Arr_Reg_Key.Item("AutoReconnect") = True Then
289-
UPS_Connect()
289+
UPS_Connect(True)
290290
End If
291291
End Select
292292
End Sub
293293

294-
Private Sub UPS_Connect()
294+
Private Sub UPS_Connect(Optional retryOnConnFailure = False)
295295
Dim Nut_Config As Nut_Parameter
296296
LogFile.LogTracing("Client UPS_Connect subroutine beginning.", LogLvl.LOG_NOTICE, Me)
297297

@@ -303,7 +303,7 @@ Public Class WinNUT
303303
Arr_Reg_Key.Item("AutoReconnect"))
304304

305305
UPS_Device = New UPS_Device(Nut_Config, LogFile, Arr_Reg_Key.Item("Delay"))
306-
UPS_Device.Connect_UPS()
306+
UPS_Device.Connect_UPS(retryOnConnFailure)
307307
End Sub
308308

309309
''' <summary>

WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ Public Class UPS_Device
5353
#End Region
5454
Private Const CosPhi As Double = 0.6
5555
' How many milliseconds to wait before the Reconnect routine tries again.
56-
#If DEBUG Then
5756
Private Const DEFAULT_RECONNECT_WAIT_MS As Double = 5000
58-
#Else
59-
Private Const DEFAULT_RECONNECT_WAIT_MS As Double = 30000
60-
#End If
6157

6258
Private WithEvents Update_Data As New Timer
6359
'Private Nut_Conn As Nut_Comm
@@ -169,7 +165,7 @@ Public Class UPS_Device
169165
'End With
170166
End Sub
171167

172-
Public Sub Connect_UPS()
168+
Public Sub Connect_UPS(Optional retryOnConnFailure = False)
173169
LogFile.LogTracing("Beginning connection: " & Nut_Config.ToString(), LogLvl.LOG_DEBUG, Me)
174170

175171
Try
@@ -185,6 +181,10 @@ Public Class UPS_Device
185181
Catch ex As Exception
186182
RaiseEvent ConnectionError(Me, ex)
187183

184+
If retryOnConnFailure Then
185+
LogFile.LogTracing("Reconnection Process Started", LogLvl.LOG_NOTICE, Me)
186+
Reconnect_Nut.Start()
187+
End If
188188
End Try
189189
End Sub
190190

0 commit comments

Comments
 (0)