Skip to content

Commit 76e8b9f

Browse files
Update SFTP status callback to output once per second (wolfSSL#779)
* Update myStatusCb to output once per second Modified the myStatusCb function in sftpclient.c to only output status updates once per second by tracking the last output time and comparing it with the current time. This reduces the frequency of status updates while maintaining all existing functionality. Co-Authored-By: [email protected] <[email protected]> * Reset status output timer when starting new file transfer When starting a new file transfer, reset the lastOutputTime to ensure the first status update for the new file is shown immediately. Co-Authored-By: [email protected] <[email protected]> * Fix Zephyr build by guarding lastOutputTime with WOLFSSH_NO_TIMESTAMP The lastOutputTime variable is only used when timestamps are enabled, so it should be guarded by the same macro to avoid unused variable warnings in builds where timestamps are disabled. Co-Authored-By: [email protected] <[email protected]> * Move elapsedTime declaration to function scope Per wolfSSL coding standards, declare all variables at function scope. Added comment explaining that modern compilers optimize variable access regardless of declaration placement. Co-Authored-By: [email protected] <[email protected]> * Fix timeout check to use elapsed time instead of current time Co-Authored-By: [email protected] <[email protected]> * Use elapsed time in timeout error message for consistency Co-Authored-By: [email protected] <[email protected]> * Move elapsedTime inside WOLFSSH_NO_TIMESTAMP guard Co-Authored-By: [email protected] <[email protected]> * Move currentTime outside WOLFSSH_NO_TIMESTAMP guard Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]>
1 parent a768c0f commit 76e8b9f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

examples/sftpclient/sftpclient.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,36 @@ static void err_msg(const char* s)
148148

149149
static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name)
150150
{
151+
/* Variables declared at function scope per wolfSSL coding standards.
152+
* Modern compilers optimize variable access regardless of declaration
153+
* placement, so there is no performance impact. */
151154
word32 currentTime;
155+
#ifndef WOLFSSH_NO_TIMESTAMP
156+
static word32 lastOutputTime = 0;
157+
word32 elapsedTime;
158+
#endif
152159
char buf[80];
153160
word64 longBytes = ((word64)bytes[1] << 32) | bytes[0];
154161

155162
#ifndef WOLFSSH_NO_TIMESTAMP
163+
currentTime = current_time(0);
164+
if (currentTime == lastOutputTime) {
165+
return;
166+
}
167+
lastOutputTime = currentTime;
156168
if (WSTRNCMP(currentFile, name, WSTRLEN(name)) != 0) {
157169
startTime = current_time(1);
170+
lastOutputTime = 0; /* Reset timer for new file transfer */
158171
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
159172
WSTRNCPY(currentFile, name, WOLFSSH_MAX_FILENAME);
160173
}
161-
currentTime = current_time(0) - startTime;
174+
elapsedTime = currentTime - startTime;
162175
WSNPRINTF(buf, sizeof(buf), "Processed %8llu\t bytes in %d seconds\r",
163-
(unsigned long long)longBytes, currentTime);
176+
(unsigned long long)longBytes, elapsedTime);
164177
#ifndef WOLFSSH_NO_SFTP_TIMEOUT
165-
if (currentTime > TIMEOUT_VALUE) {
178+
if (elapsedTime > TIMEOUT_VALUE) {
166179
WSNPRINTF(buf, sizeof(buf), "\nProcess timed out at %d seconds, "
167-
"stopping\r", currentTime);
180+
"stopping\r", elapsedTime);
168181
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
169182
wolfSSH_SFTP_Interrupt(ssh);
170183
}

0 commit comments

Comments
 (0)