Renamed sum_table -> hash_table.
[rsync/rsync.git] / io.c
diff --git a/io.c b/io.c
index dd99913..475ac40 100644 (file)
--- a/io.c
+++ b/io.c
@@ -41,7 +41,6 @@
 
 extern int bwlimit;
 extern size_t bwlimit_writemax;
-extern int verbose;
 extern int io_timeout;
 extern int allowed_lull;
 extern int am_server;
@@ -105,6 +104,8 @@ static char io_filesfrom_lastchar;
 static int io_filesfrom_buflen;
 static size_t contiguous_write_len = 0;
 static int select_timeout = SELECT_TIMEOUT;
+static int active_filecnt = 0;
+static OFF_T active_bytecnt = 0;
 
 static void read_loop(int fd, char *buf, size_t len);
 
@@ -279,6 +280,8 @@ static void read_msg_fd(void)
                        exit_cleanup(RERR_STREAMIO);
                }
                read_loop(fd, buf, 4);
+               if (remove_sent_files)
+                       decrement_active_files(IVAL(buf,0));
                flist_ndx_push(&redo_list, IVAL(buf,0));
                break;
        case MSG_DELETED:
@@ -295,8 +298,10 @@ static void read_msg_fd(void)
                        exit_cleanup(RERR_STREAMIO);
                }
                read_loop(fd, buf, len);
-               if (remove_sent_files)
+               if (remove_sent_files) {
+                       decrement_active_files(IVAL(buf,0));
                        io_multiplex_write(MSG_SUCCESS, buf, len);
+               }
                if (preserve_hard_links)
                        flist_ndx_push(&hlink_list, IVAL(buf,0));
                break;
@@ -327,6 +332,28 @@ static void read_msg_fd(void)
        msg_fd_in = fd;
 }
 
+/* This is used by the generator to limit how many file transfers can
+ * be active at once when --remove-sent-files is specified.  Without
+ * this, sender-side deletions were mostly happening at the end. */
+void increment_active_files(int ndx, int itemizing, enum logcode code)
+{
+       /* TODO: tune these limits? */
+       while (active_filecnt >= (active_bytecnt >= 128*1024 ? 10 : 50)) {
+               if (hlink_list.head)
+                       check_for_finished_hlinks(itemizing, code);
+               read_msg_fd();
+       }
+
+       active_filecnt++;
+       active_bytecnt += the_file_list->files[ndx]->length;
+}
+
+void decrement_active_files(int ndx)
+{
+       active_filecnt--;
+       active_bytecnt -= the_file_list->files[ndx]->length;
+}
+
 /* Try to push messages off the list onto the wire.  If we leave with more
  * to do, return 0.  On error, return -1.  If everything flushed, return 1.
  * This is only active in the receiver. */
@@ -921,6 +948,11 @@ int read_vstring(int f, char *buf, int bufsize)
 void read_sum_head(int f, struct sum_struct *sum)
 {
        sum->count = read_int(f);
+       if (sum->count < 0) {
+               rprintf(FERROR, "Invalid checksum count %ld [%s]\n",
+                       (long)sum->count, who_am_i());
+               exit_cleanup(RERR_PROTOCOL);
+       }
        sum->blength = read_int(f);
        if (sum->blength < 0 || sum->blength > MAX_BLOCK_SIZE) {
                rprintf(FERROR, "Invalid block length %ld [%s]\n",
@@ -983,7 +1015,7 @@ static void sleep_for_bwlimit(int bytes_written)
 
 #define ONE_SEC        1000000L /* # of microseconds in a second */
 
-       if (!bwlimit)
+       if (!bwlimit_writemax)
                return;
 
        total_written += bytes_written; 
@@ -1063,7 +1095,7 @@ static void writefd_unbuffered(int fd,char *buf,size_t len)
                        continue;
 
                n = len - total;
-               if (bwlimit && n > bwlimit_writemax)
+               if (bwlimit_writemax && n > bwlimit_writemax)
                        n = bwlimit_writemax;
                cnt = write(fd, buf + total, n);