From c00a90da197d5c7be3ccd7497c6b8cefc0432053 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Thu, 4 Apr 2002 19:39:30 +0000 Subject: [PATCH] Binkp transfer times in mSecs. (experimental) --- ChangeLog | 1 + mbcico/binkp.c | 34 +++++++++++++++++----------------- mbcico/filelist.c | 18 ++++++++++++++++++ mbcico/filelist.h | 3 +++ 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 31d9fab0..0665b398 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4738,6 +4738,7 @@ v0.33.20 10-Feb-2002 Added experimental support for binkp GET command frame, under test now. Registers TCP/IP sessions with mbtask. + Experimental: binkp filetransfer times are calculated in mSec. mbout: The status display has now 9 digits for the outbound size. diff --git a/mbcico/binkp.c b/mbcico/binkp.c index 0da838a2..5745da30 100644 --- a/mbcico/binkp.c +++ b/mbcico/binkp.c @@ -811,8 +811,6 @@ int binkp_batch(file_list *to_send) int rxlen = 0, txlen = 0; long txpos = 0, rxpos = 0; long stxpos = 0; - time_t rxstarttime, rxendtime; - time_t txstarttime, txendtime; int sverr, cmd = FALSE, GotFrame = FALSE; int blklen = 0, c, Found = FALSE; unsigned short header = 0; @@ -823,6 +821,15 @@ int binkp_batch(file_list *to_send) long written; binkp_list *bll = NULL, *tmp, *tmpg, *cursend = NULL; file_list *tsl; + struct timeval rxtvstart, rxtvend; + struct timeval txtvstart, txtvend; + struct timezone tz; + + rxtvstart.tv_sec = rxtvstart.tv_usec = 0; + rxtvend.tv_sec = rxtvend.tv_usec = 0; + txtvstart.tv_sec = txtvstart.tv_usec = 0; + txtvend.tv_sec = txtvend.tv_usec = 0; + tz.tz_minuteswest = tz.tz_dsttime = 0; batchnr++; Syslog('+', "Binkp: starting batch %d", batchnr); @@ -837,7 +844,6 @@ int binkp_batch(file_list *to_send) binkp_settimer(BINKP_TIMEOUT); nethold = mailhold = 0L; transferred = FALSE; - rxstarttime = txstarttime = time(NULL); /* * Build a new filelist from the existing filelist. @@ -950,7 +956,7 @@ int binkp_batch(file_list *to_send) Syslog('+', "Binkp: size %lu bytes, dated %s", (unsigned long)tmp->size, date(tmp->date)); binkp_send_control(MM_FILE, "%s %lu %ld %ld", MBSE_SS(tmp->remote), (unsigned long)tmp->size, (long)tmp->date, (unsigned long)tmp->offset); - txstarttime = time(NULL); + gettimeofday(&txtvstart, &tz); tmp->state = Sending; cursend = tmp; TxState = TxTryRead; @@ -998,10 +1004,7 @@ int binkp_batch(file_list *to_send) /* * calculate time needed and bytes transferred */ - txendtime = time(NULL); - txstarttime = txendtime - txstarttime; - if (txstarttime <= 0L) - txstarttime = 1L; + gettimeofday(&txtvend, &tz); /* * Close transmitter file @@ -1010,10 +1013,10 @@ int binkp_batch(file_list *to_send) if (txpos >= 0) { stxpos = txpos - stxpos; - Syslog('+', "Binkp: OK %lu bytes send in %s (%ld cps)", - stxpos, str_time(txstarttime), stxpos/txstarttime); + Syslog('+', "Binkp: OK %s", transfertime(txtvstart, txtvend, stxpos, TRUE)); } else { - Syslog('+', "Binkp: transmitter skipped file after %ld seconds", txstarttime); + Syslog('+', "Binkp: transmitter skipped file after %ld seconds", + txtvend.tv_sec - txtvstart.tv_sec); } cursend->state = IsSent; @@ -1124,11 +1127,8 @@ int binkp_batch(file_list *to_send) binkp_send_control(MM_GOT, "%s %ld %ld", rname, rsize, rtime); closefile(TRUE); rxpos = rxpos - rxbytes; - rxendtime = time(NULL); - if ((rxstarttime = rxendtime - rxstarttime) == 0L) - rxstarttime = 1L; - Syslog('+', "Binkp: received OK %lu bytes in %s (%ld cps)", - rxpos, str_time(rxstarttime), rxpos / rxstarttime); + gettimeofday(&rxtvend, &tz); + Syslog('+', "Binkp: OK %s", transfertime(rxtvstart, rxtvend, rxpos, FALSE)); rcvdbytes += rxpos; RxState = RxWaitFile; transferred = TRUE; @@ -1151,7 +1151,7 @@ int binkp_batch(file_list *to_send) case RxAcceptFile: Syslog('+', "Binkp: receive file \"%s\" date %s size %ld offset %ld", rname, date(rtime), rsize, roffs); rxfp = openfile(rname, rtime, rsize, &rxbytes, resync); - rxstarttime = time(NULL); + gettimeofday(&rxtvstart, &tz); rxpos = 0; if (!diskfree(CFG.freespace)) { diff --git a/mbcico/filelist.c b/mbcico/filelist.c index f9061034..e67864c2 100644 --- a/mbcico/filelist.c +++ b/mbcico/filelist.c @@ -474,3 +474,21 @@ void execute_disposition(file_list *fl) } + +char *transfertime(struct timeval start, struct timeval end, long bytes, int sent) +{ + static char resp[81]; + long startms, endms, elapsed; + + memset(&resp, 0, sizeof(resp)); + startms = (start.tv_sec * 1000) + (start.tv_usec / 1000); + endms = (end.tv_sec * 1000) + (end.tv_usec / 1000); + elapsed = endms - startms; + if (!elapsed) + elapsed = 1L; + sprintf(resp, "%ld bytes %s in %0.3f seconds (%ld cps)", + bytes, sent?"sent":"received", elapsed / 1000.000, (bytes * 1000) / elapsed); + return resp; +} + + diff --git a/mbcico/filelist.h b/mbcico/filelist.h index 83afe41d..142f7329 100644 --- a/mbcico/filelist.h +++ b/mbcico/filelist.h @@ -1,3 +1,5 @@ +/* $Id$ */ + #ifndef _FILELIST_H #define _FILELIST_H @@ -7,6 +9,7 @@ file_list *create_filelist(fa_list *, char *, int); file_list *create_freqlist(fa_list *); void tidy_filelist(file_list *, int); void execute_disposition(file_list *); +char *transfertime(struct timeval, struct timeval, long, int); #endif