use word32 type with timeout example

pull/284/head
Jacob Barthelmeh 2020-09-30 11:45:33 -06:00
parent 69b91a3a2e
commit a4b2c693fe
1 changed files with 10 additions and 9 deletions

View File

@ -56,26 +56,27 @@ static void err_msg(const char* s)
#include <sys/time.h> #include <sys/time.h>
static char currentFile[WOLFSSH_MAX_FILENAME+1] = ""; static char currentFile[WOLFSSH_MAX_FILENAME+1] = "";
static double startTime; static word32 startTime;
#define TIMEOUT_VALUE 120 #define TIMEOUT_VALUE 120
double current_time(int); word32 current_time(int);
double current_time(int reset)
/* return number of seconds*/
word32 current_time(int reset)
{ {
struct timeval tv; struct timeval tv;
(void)reset; (void)reset;
gettimeofday(&tv, 0); gettimeofday(&tv, 0);
return (word32)tv.tv_sec;
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000;
} }
#endif #endif
static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name) static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name)
{ {
double currentTime; word32 currentTime;
char buf[80]; char buf[80];
word64 longBytes = ((word64)bytes[1] << 32) | bytes[0]; word64 longBytes = ((word64)bytes[1] << 32) | bytes[0];
@ -86,11 +87,11 @@ static void myStatusCb(WOLFSSH* sshIn, word32* bytes, char* name)
WSTRNCPY(currentFile, name, WOLFSSH_MAX_FILENAME); WSTRNCPY(currentFile, name, WOLFSSH_MAX_FILENAME);
} }
currentTime = current_time(0) - startTime; currentTime = current_time(0) - startTime;
WSNPRINTF(buf, sizeof(buf), "Processed %8llu\t bytes in %.2f seconds\r", WSNPRINTF(buf, sizeof(buf), "Processed %8llu\t bytes in %d seconds\r",
(unsigned long long)longBytes, currentTime); (unsigned long long)longBytes, currentTime);
if (currentTime > TIMEOUT_VALUE) { if (currentTime > TIMEOUT_VALUE) {
WSNPRINTF(buf, sizeof(buf), "\nProcess timed out at %.2fs, stopping\r", WSNPRINTF(buf, sizeof(buf), "\nProcess timed out at %d seconds, "
currentTime); "stopping\r", currentTime);
WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME); WMEMSET(currentFile, 0, WOLFSSH_MAX_FILENAME);
wolfSSH_SFTP_Interrupt(ssh); wolfSSH_SFTP_Interrupt(ssh);
} }