Blame SOURCES/0025-Improve-local_max_rate-option.patch

90e381
From 386db86fe865fb552b1867af4bf4b78dbf9080cf Mon Sep 17 00:00:00 2001
90e381
From: Martin Sehnoutka <msehnout@redhat.com>
90e381
Date: Thu, 17 Nov 2016 12:44:26 +0100
90e381
Subject: [PATCH 25/59] Improve local_max_rate option.
90e381
90e381
Now it should work as expected.
90e381
---
90e381
 ftpdataio.c | 14 +++++++-------
90e381
 main.c      |  2 +-
90e381
 session.h   |  3 ++-
90e381
 3 files changed, 10 insertions(+), 9 deletions(-)
90e381
90e381
diff --git a/ftpdataio.c b/ftpdataio.c
90e381
index 3e4e9c9..00f9021 100644
90e381
--- a/ftpdataio.c
90e381
+++ b/ftpdataio.c
90e381
@@ -249,7 +249,7 @@ handle_io(int retval, int fd, void* p_private)
90e381
 {
90e381
   long curr_sec;
90e381
   long curr_usec;
90e381
-  unsigned int bw_rate;
90e381
+  unsigned long bw_rate;
90e381
   double elapsed;
90e381
   double pause_time;
90e381
   double rate_ratio;
90e381
@@ -276,19 +276,16 @@ handle_io(int retval, int fd, void* p_private)
90e381
   {
90e381
     elapsed = (double) 0.01;
90e381
   }
90e381
-  bw_rate = (unsigned int) ((double) retval / elapsed);
90e381
-  if (bw_rate <= p_sess->bw_rate_max)
90e381
+  p_sess->bw_retval += retval;
90e381
+  bw_rate = (unsigned long) ((double) p_sess->bw_retval / elapsed);
90e381
+  if (bw_rate <= p_sess->bw_rate_max || p_sess->bw_retval < (unsigned long)(10*retval))
90e381
   {
90e381
-    p_sess->bw_send_start_sec = curr_sec;
90e381
-    p_sess->bw_send_start_usec = curr_usec;
90e381
     return;
90e381
   }
90e381
   /* Tut! Rate exceeded, calculate a pause to bring things back into line */
90e381
   rate_ratio = (double) bw_rate / (double) p_sess->bw_rate_max;
90e381
   pause_time = (rate_ratio - (double) 1) * elapsed;
90e381
   vsf_sysutil_sleep(pause_time);
90e381
-  p_sess->bw_send_start_sec = vsf_sysutil_get_time_sec();
90e381
-  p_sess->bw_send_start_usec = vsf_sysutil_get_time_usec();
90e381
 }
90e381
 
90e381
 int
90e381
@@ -441,6 +438,9 @@ struct vsf_transfer_ret
90e381
 vsf_ftpdataio_transfer_file(struct vsf_session* p_sess, int remote_fd,
90e381
                             int file_fd, int is_recv, int is_ascii)
90e381
 {
90e381
+  p_sess->bw_send_start_sec = vsf_sysutil_get_time_sec();
90e381
+  p_sess->bw_send_start_usec = vsf_sysutil_get_time_usec();
90e381
+  p_sess->bw_retval = 0;
90e381
   if (!is_recv)
90e381
   {
90e381
     if (is_ascii || p_sess->data_use_ssl)
90e381
diff --git a/main.c b/main.c
90e381
index eaba265..f1e2f69 100644
90e381
--- a/main.c
90e381
+++ b/main.c
9b0ebb
@@ -40,7 +40,7 @@
90e381
     /* Control connection */
9b0ebb
     0, 0, 0, 0, 0, 0,
90e381
     /* Data connection */
90e381
-    -1, 0, -1, 0, 0, 0, 0,
90e381
+    -1, 0, -1, 0, 0, 0, 0, 0,
90e381
     /* Login */
90e381
     1, 0, INIT_MYSTR, INIT_MYSTR,
90e381
     /* Protocol state */
90e381
diff --git a/session.h b/session.h
90e381
index 956bfb7..3e8fdd5 100644
90e381
--- a/session.h
90e381
+++ b/session.h
90e381
@@ -29,9 +29,10 @@ struct vsf_session
90e381
   struct vsf_sysutil_sockaddr* p_port_sockaddr;
90e381
   int data_fd;
90e381
   int data_progress;
90e381
-  unsigned int bw_rate_max;
90e381
+  unsigned long bw_rate_max;
90e381
   long bw_send_start_sec;
90e381
   long bw_send_start_usec;
90e381
+  unsigned long bw_retval;
90e381
 
90e381
   /* Details of the login */
90e381
   int is_anonymous;
90e381
-- 
90e381
2.14.4
90e381