mirror of https://github.com/wolfSSL/wolfssh.git
Update SFTP status callback to output once per second (#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: andrew@wolfssl.com <andrew@wolfssl.com> * 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: andrew@wolfssl.com <andrew@wolfssl.com> * 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: andrew@wolfssl.com <andrew@wolfssl.com> * 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: andrew@wolfssl.com <andrew@wolfssl.com> * Fix timeout check to use elapsed time instead of current time Co-Authored-By: andrew@wolfssl.com <andrew@wolfssl.com> * Use elapsed time in timeout error message for consistency Co-Authored-By: andrew@wolfssl.com <andrew@wolfssl.com> * Move elapsedTime inside WOLFSSH_NO_TIMESTAMP guard Co-Authored-By: andrew@wolfssl.com <andrew@wolfssl.com> * Move currentTime outside WOLFSSH_NO_TIMESTAMP guard Co-Authored-By: andrew@wolfssl.com <andrew@wolfssl.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: andrew@wolfssl.com <andrew@wolfssl.com>pull/788/head
parent
a768c0f640
commit
76e8b9f4ea
|
|
@ -148,23 +148,36 @@ static void err_msg(const char* s)
|
|||
|
||||
static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name)
|
||||
{
|
||||
/* Variables declared at function scope per wolfSSL coding standards.
|
||||
* Modern compilers optimize variable access regardless of declaration
|
||||
* placement, so there is no performance impact. */
|
||||
word32 currentTime;
|
||||
#ifndef WOLFSSH_NO_TIMESTAMP
|
||||
static word32 lastOutputTime = 0;
|
||||
word32 elapsedTime;
|
||||
#endif
|
||||
char buf[80];
|
||||
word64 longBytes = ((word64)bytes[1] << 32) | bytes[0];
|
||||
|
||||
#ifndef WOLFSSH_NO_TIMESTAMP
|
||||
currentTime = current_time(0);
|
||||
if (currentTime == lastOutputTime) {
|
||||
return;
|
||||
}
|
||||
lastOutputTime = currentTime;
|
||||
if (WSTRNCMP(currentFile, name, WSTRLEN(name)) != 0) {
|
||||
startTime = current_time(1);
|
||||
lastOutputTime = 0; /* Reset timer for new file transfer */
|
||||
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
|
||||
WSTRNCPY(currentFile, name, WOLFSSH_MAX_FILENAME);
|
||||
}
|
||||
currentTime = current_time(0) - startTime;
|
||||
elapsedTime = currentTime - startTime;
|
||||
WSNPRINTF(buf, sizeof(buf), "Processed %8llu\t bytes in %d seconds\r",
|
||||
(unsigned long long)longBytes, currentTime);
|
||||
(unsigned long long)longBytes, elapsedTime);
|
||||
#ifndef WOLFSSH_NO_SFTP_TIMEOUT
|
||||
if (currentTime > TIMEOUT_VALUE) {
|
||||
if (elapsedTime > TIMEOUT_VALUE) {
|
||||
WSNPRINTF(buf, sizeof(buf), "\nProcess timed out at %d seconds, "
|
||||
"stopping\r", currentTime);
|
||||
"stopping\r", elapsedTime);
|
||||
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
|
||||
wolfSSH_SFTP_Interrupt(ssh);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue