changeset 220:6de9a8280aa4

2003-7-10 Brian Masney <masneyb@gftp.org> * lib/misc.c (insert_commas) - improved calculating # of digits in number. (Not sure if this worked properly for long long's, aka off_t when _LARGEFILE_SOURCE is defined) * src/gtk/transfer.c (update_file_status) - changed type of remaining field to be off_t. (hopefully fixes >2.1GB problem) * lib/protocols.c (gftp_calc_kbs) - improved throttling module.
author masneyb
date Fri, 11 Jul 2003 01:48:08 +0000
parents b9584a877daf
children c0d7f3b6e8cb
files ChangeLog lib/misc.c lib/protocols.c src/gtk/transfer.c
diffstat 4 files changed, 51 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jul 09 23:25:57 2003 +0000
+++ b/ChangeLog	Fri Jul 11 01:48:08 2003 +0000
@@ -1,3 +1,13 @@
+2003-7-10 Brian Masney <masneyb@gftp.org>
+	* lib/misc.c (insert_commas) - improved calculating # of digits
+	in number. (Not sure if this worked properly for long long's, aka
+	off_t when _LARGEFILE_SOURCE is defined)
+
+	* src/gtk/transfer.c (update_file_status) - changed type of remaining
+	field to be off_t. (hopefully fixes >2.1GB problem)
+
+	* lib/protocols.c (gftp_calc_kbs) - improved throttling module.
+
 2003-7-9 Brian Masney <masneyb@gftp.org>
 	* lib/sshv2.c - if we are logging in to the server, and the message 
 	size is too big from the server, assume that an error message follows
@@ -1247,7 +1257,7 @@
 
 	* cvsclean - added this script
 
-	* *.[ch] - added $Id: ChangeLog,v 1.111 1997/01/01 09:22:34 masneyb Exp $ tags
+	* *.[ch] - added $Id: ChangeLog,v 1.112 2003/07/11 01:48:07 masneyb Exp $ tags
 
 	* debian/* - updated files from Debian maintainer
 
--- a/lib/misc.c	Wed Jul 09 23:25:57 2003 +0000
+++ b/lib/misc.c	Fri Jul 11 01:48:08 2003 +0000
@@ -29,11 +29,17 @@
   char *frompos, *topos, src[50], *dest;
   int len, num, rem, i;
 
+#if defined (_LARGEFILE_SOURCE)
+  g_snprintf (src, sizeof (src), "%lld", number);
+#else
+  g_snprintf (src, sizeof (src), "%ld", number);
+#endif
+
   if (dest_str != NULL)
     *dest_str = '\0';
-  len = (number > 0 ? log10 (number) : 0) + 2;
 
-  if (len <= 0) 
+  len = strlen (src);
+  if (len == 0)
     {
       if (dest_str != NULL)
         strncpy (dest_str, "0", dest_len);
@@ -43,6 +49,7 @@
     }
 
   len += len / 3;
+
   if (dest_str != NULL && len > dest_len)
     {
       
@@ -57,12 +64,6 @@
   else
     dest = dest_str;
 
-#if defined (_LARGEFILE_SOURCE)
-  g_snprintf (src, sizeof (src), "%lld", number);
-#else
-  g_snprintf (src, sizeof (src), "%ld", number);
-#endif
-
   num = strlen (src) / 3 - 1;
   rem = strlen (src) % 3;
   frompos = src;
--- a/lib/protocols.c	Wed Jul 09 23:25:57 2003 +0000
+++ b/lib/protocols.c	Fri Jul 11 01:48:08 2003 +0000
@@ -2299,46 +2299,39 @@
 gftp_calc_kbs (gftp_transfer * tdata, ssize_t num_read)
 {
   unsigned long waitusecs;
-  double difftime, curkbs;
+  double start_difftime;
   gftp_file * tempfle;
-  unsigned long toadd;
   struct timeval tv;
   float maxkbs;
 
   gftp_lookup_request_option (tdata->fromreq, "maxkbs", &maxkbs);
 
-  gettimeofday (&tv, NULL);
   if (g_thread_supported ())
     g_static_mutex_lock (&tdata->statmutex);
 
+  gettimeofday (&tv, NULL);
+
   tempfle = tdata->curfle->data;
   tdata->trans_bytes += num_read;
   tdata->curtrans += num_read;
   tdata->stalled = 0;
 
-  difftime = (tv.tv_sec - tdata->starttime.tv_sec) + ((double) (tv.tv_usec - tdata->starttime.tv_usec) / 1000000.0);
-  if (difftime <= 0)
-    tdata->kbs = (double) tdata->trans_bytes / 1024.0;
+  start_difftime = (tv.tv_sec - tdata->starttime.tv_sec) + ((double) (tv.tv_usec - tdata->starttime.tv_usec) / 1000000.0);
+
+  if (start_difftime <= 0)
+    tdata->kbs = tdata->trans_bytes / 1024.0;
   else
-    tdata->kbs = (double) tdata->trans_bytes / 1024.0 / difftime;
-
-  difftime = (tv.tv_sec - tdata->lasttime.tv_sec) + ((double) (tv.tv_usec - tdata->lasttime.tv_usec) / 1000000.0);
-
-  if (difftime <= 0)
-    curkbs = (double) (num_read / 1024.0);
-  else
-    curkbs = (double) (num_read / 1024.0 / difftime);
-
-  if (maxkbs > 0 && curkbs > maxkbs)
+    tdata->kbs = tdata->trans_bytes / 1024.0 / start_difftime;
+
+  if (maxkbs > 0 && tdata->kbs > maxkbs)
     {
-      waitusecs = (double) num_read / 1024.0 / maxkbs * 1000000.0 - difftime;
+      waitusecs = num_read / 1024.0 / maxkbs * 1000000.0 - start_difftime;
 
       if (waitusecs > 0)
         {
           if (g_thread_supported ())
             g_static_mutex_unlock (&tdata->statmutex);
 
-          difftime += ((double) waitusecs / 1000000.0);
           usleep (waitusecs);
 
           if (g_thread_supported ())
@@ -2346,13 +2339,7 @@
         }
     }
 
-  /* I don't call gettimeofday (&tdata->lasttime) here because this will use
-     less system resources. This will be close enough for what we need */
-  difftime += tdata->lasttime.tv_usec / 1000000.0;
-  toadd = (long) difftime;
-  difftime -= toadd;
-  tdata->lasttime.tv_sec += toadd;
-  tdata->lasttime.tv_usec = difftime * 1000000.0;
+  gettimeofday (&tdata->lasttime, NULL);
 
   if (g_thread_supported ())
     g_static_mutex_unlock (&tdata->statmutex);
--- a/src/gtk/transfer.c	Wed Jul 09 23:25:57 2003 +0000
+++ b/src/gtk/transfer.c	Fri Jul 11 01:48:08 2003 +0000
@@ -1293,7 +1293,7 @@
 {
   char totstr[100], dlstr[100], gotstr[50], ofstr[50];
   int hours, mins, secs, pcent, st;
-  double remaining;
+  off_t remaining_secs;
   gftp_file * tempfle;
   struct timeval tv;
 
@@ -1301,15 +1301,16 @@
   tempfle = tdata->curfle->data;
 
   gettimeofday (&tv, NULL);
-  if ((remaining = (double) (tv.tv_sec - tdata->starttime.tv_sec) + ((double) (tv.tv_usec - tdata->starttime.tv_usec) / 1000000.0)) == 0)
-    remaining = 1.0;
+
+  remaining_secs = (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes) / 1024;
+  if (tdata->kbs > 0)
+    remaining_secs /= (off_t) tdata->kbs;
 
-  remaining = ((double) (tdata->total_bytes - tdata->trans_bytes - tdata->resumed_bytes)) / 1024.0 / tdata->kbs;
-  hours = (off_t) remaining / 3600;
-  remaining -= hours * 3600;
-  mins = (off_t) remaining / 60;
-  remaining -= mins * 60;
-  secs = (off_t) remaining;
+  hours = remaining_secs / 3600;
+  remaining_secs -= hours * 3600;
+  mins = remaining_secs / 60;
+  remaining_secs -= mins * 60;
+  secs = remaining_secs;
 
   if (hours < 0 || mins < 0 || secs < 0)
     {
@@ -1336,12 +1337,15 @@
         {
           if (tdata->curfle->next != NULL)
             {
-              remaining = ((double) (tempfle->size - tdata->curtrans - tdata->curresumed)) / 1024.0 / tdata->kbs;
-              hours = (off_t) remaining / 3600;
-              remaining -= hours * 3600;
-              mins = (off_t) remaining / 60;
-              remaining -= mins * 60;
-              secs = (off_t) remaining;
+              remaining_secs = (tempfle->size - tdata->curtrans - tdata->curresumed) / 1024;
+              if (tdata->kbs > 0)
+                remaining_secs /= (off_t) tdata->kbs;
+
+              hours = remaining_secs / 3600;
+              remaining_secs -= hours * 3600;
+              mins = remaining_secs / 60;
+              remaining_secs -= mins * 60;
+              secs = remaining_secs;
             }
 
           if (!(hours < 0 || mins < 0 || secs < 0))