Skip to content

Commit 223aeb3

Browse files
committed
- remove need for m_timerCount by using initial option of CreateTimerQueueTimer()
- adapted timer drifts correction value to 2 seconds initially and 1s for repeats - made method const - avoid warning about unused param TimerOrWaitFired
1 parent de40c89 commit 223aeb3

2 files changed

Lines changed: 12 additions & 22 deletions

File tree

src/FTPSession.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "FTPWindow.h"
2323

24-
void CALLBACK FTPSessionTimerProc(PVOID lpHandle, BOOLEAN TimerOrWaitFired) {
24+
void CALLBACK FTPSessionTimerProc(PVOID lpHandle, BOOLEAN /*TimerOrWaitFired*/) {
2525
FTPSession* obj = (FTPSession*) lpHandle;
2626
obj->QueueTimerHandler();
2727
}
@@ -66,7 +66,6 @@ int FTPSession::Init(FTPWindow * ftpWindow, FTPSettings * ftpSettings) {
6666
m_isInit = true;
6767

6868
m_timerHandle = NULL;
69-
m_timerCount = 0;
7069
m_timerIsInit = false;
7170

7271
return 0;
@@ -143,7 +142,6 @@ int FTPSession::TerminateSession() {
143142
if (m_timerIsInit) {
144143
OutDebug("[FTPSession] Deleting session timer");
145144
DeleteTimerQueueTimer(NULL, m_timerHandle, NULL);
146-
m_timerCount = 0;
147145
OutDebug("[FTPSession] Successfully deleted session timer");
148146

149147
m_timerIsInit = false;
@@ -163,7 +161,7 @@ int FTPSession::TerminateSession() {
163161
return 0;
164162
}
165163

166-
bool FTPSession::IsConnected() {
164+
bool FTPSession::IsConnected() const {
167165
return m_running;
168166
}
169167

@@ -192,8 +190,8 @@ int FTPSession::Connect() {
192190
NULL,
193191
(WAITORTIMERCALLBACK) FTPSessionTimerProc,
194192
this,
195-
0,
196-
(m_currentProfile->GetNoOp() * 1000) + 500,
193+
(m_currentProfile->GetNoOp() * 1000) + 2000,
194+
(m_currentProfile->GetNoOp() * 1000) + 1000,
197195
WT_EXECUTEINTIMERTHREAD
198196
);
199197

@@ -209,28 +207,21 @@ int FTPSession::Connect() {
209207

210208

211209
void FTPSession::QueueTimerHandler() {
212-
// don't call on first immediate run
213-
if (m_timerCount++ == 0) {
214-
return;
215-
}
216-
210+
217211
// don't call if last action has been recently run
218212
DWORD mainSecs = m_mainWrapper->LastAction();
219213
DWORD transSecs = m_transferWrapper->LastAction();
220-
214+
221215
if (mainSecs == 0 && transSecs == 0) {
222216
OutDebug("[FTPSession] Both main/trans wrappers report 0 seconds since last action");
223217
return;
224218
}
225-
226-
DWORD minSecs = mainSecs;
227-
if (transSecs < mainSecs) {
228-
minSecs = transSecs;
229-
}
230-
219+
220+
DWORD minSecs = min(mainSecs, transSecs);
221+
231222
OutDebug("[FTPSession] There has been %d seconds since last action with server", minSecs);
232-
233-
if (minSecs > (DWORD) m_currentProfile->GetNoOp()) {
223+
224+
if (minSecs >= (DWORD) m_currentProfile->GetNoOp()) {
234225
OutDebug("[FTPSession] Running NOOP");
235226
NoOp();
236227
}

src/FTPSession.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class FTPSession {
4040
int StartSession(FTPProfile * sessionProfile);
4141
int TerminateSession();
4242

43-
bool IsConnected();
43+
bool IsConnected() const;
4444
const FTPProfile* GetCurrentProfile();
4545

4646
int Connect();
@@ -78,7 +78,6 @@ class FTPSession {
7878
int Clear();
7979

8080
HANDLE m_timerHandle = NULL;
81-
int m_timerCount = 0;
8281
bool m_timerIsInit = false;
8382

8483
FTPProfile* m_currentProfile;

0 commit comments

Comments
 (0)