added hooks for compression in token.c
authorAndrew Tridgell <tridge@samba.org>
Mon, 1 Jul 1996 05:55:05 +0000 (05:55 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 1 Jul 1996 05:55:05 +0000 (05:55 +0000)
.cvsignore
Makefile.in
main.c
match.c
rsync.c
token.c [new file with mode: 0644]

index 51a6d58..1c8e87b 100644 (file)
@@ -50,6 +50,10 @@ rsync-1.4.1
 rsync-1.4.1.tar.gz
 rsync-1.4.2
 rsync-1.4.2.tar.gz
+rsync-1.4.3
+rsync-1.4.4
+rsync-1.4.5
+rsync-1.4.5.tar.gz
 rsync-1.4.tar.gz
 rsync-ERSION
 rsync.aux
@@ -60,5 +64,3 @@ tech_report.dvi
 tech_report.log
 tech_report.ps
 test
-rsync-1.4.3
-rsync-1.4.4
index b0a1f8f..157f570 100644 (file)
@@ -21,7 +21,7 @@ SHELL=/bin/sh
 
 LIBOBJ=lib/getopt.o lib/fnmatch.o 
 OBJS1=rsync.o exclude.o util.o md4.o main.o checksum.o match.o 
-OBJS=$(OBJS1) flist.o io.o compat.o hlink.o $(LIBOBJ)
+OBJS=$(OBJS1) flist.o io.o compat.o hlink.o token.o $(LIBOBJ)
 
 .c.o:
        $(CC) $(CFLAGS) -c $*.c -o $*.o
diff --git a/main.c b/main.c
index 1619451..3efde6d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -46,6 +46,8 @@ int delete_mode=0;
 int one_file_system=0;
 int remote_version=0;
 int sparse_files=0;
+int do_compression=0;
+
 extern int csum_length;
 
 int am_server = 0;
diff --git a/match.c b/match.c
index 971fa10..6590178 100644 (file)
--- a/match.c
+++ b/match.c
@@ -98,17 +98,13 @@ static void matched(int f,struct sum_struct *s,char *buf,off_t len,
       fprintf(FERROR,"match at %d last_match=%d j=%d len=%d n=%d\n",
              (int)offset,(int)last_match,i,(int)s->sums[i].len,n);
 
-  if (n > 0) {
-    int l = 0;
-    write_int(f,n);
-    while (l < n) {
-      int n1 = MIN(CHUNK_SIZE,n-l);
-      write_buf(f,map_ptr(buf,last_match+l,n1),n1);
-      l += n1;
-    }
-    data_transfer += n;
-  }
-  write_int(f,-(i+1));
+  send_token(f,i,buf,last_match,n);
+
+  data_transfer += n;
+
+  if (i != -1)
+    last_match = offset + s->sums[i].len;
+  
   if (i != -1)
     last_match = offset + s->sums[i].len;
   if (n > 0)
diff --git a/rsync.c b/rsync.c
index 5ae3695..73589d0 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -402,17 +402,18 @@ static void receive_data(int f_in,char *buf,int fd,char *fname)
   int i,n,remainder,len,count;
   off_t offset = 0;
   off_t offset2;
+  char *data;
 
   count = read_int(f_in);
   n = read_int(f_in);
   remainder = read_int(f_in);
 
-  for (i=read_int(f_in); i != 0; i=read_int(f_in)) {
+  for (i=recv_token(f_in,&data); i != 0; i=recv_token(f_in,&data)) {
     if (i > 0) {
       if (verbose > 3)
        fprintf(FERROR,"data recv %d at %d\n",i,(int)offset);
 
-      if (read_write(f_in,fd,i) != i) {
+      if (write_sparse(fd,data,i) != i) {
        fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
        exit_cleanup(1);
       }
diff --git a/token.c b/token.c
new file mode 100644 (file)
index 0000000..630c393
--- /dev/null
+++ b/token.c
@@ -0,0 +1,101 @@
+/* 
+   Copyright (C) Andrew Tridgell 1996
+   Copyright (C) Paul Mackerras 1996
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "rsync.h"
+
+extern int do_compression;
+
+
+/* non-compressing recv token */
+static int simple_recv_token(int f,char **data)
+{
+  static int residue = 0;
+  static char *buf = NULL;
+  int n;
+
+  if (!buf) {
+    buf = (char *)malloc(CHUNK_SIZE);
+    if (!buf) out_of_memory("simple_recv_token");
+  }
+
+
+  if (residue == 0) {
+    int i = read_int(f);
+    if (i <= 0) return i;
+    residue = i;
+  }
+
+  *data = buf;
+  n = MIN(CHUNK_SIZE,residue);
+  residue -= n;
+  read_buf(f,buf,n);
+  return n;
+}
+
+
+/* non-compressing send token */
+static void simple_send_token(int f,int token,char *buf,int offset,int n)
+{
+  if (n > 0) {
+    int l = 0;
+    while (l < n) {
+      int n1 = MIN(CHUNK_SIZE,n-l);
+      write_int(f,n1);
+      write_buf(f,map_ptr(buf,offset+l,n1),n1);
+      l += n1;
+    }
+  }
+  write_int(f,-(token+1));
+}
+
+
+
+
+/*
+ * transmit a verbatim buffer of length n followed by a token 
+ * If token == -1 then we have reached EOF 
+ * If n == 0 then don't send a buffer
+ * Note that "buf" must be used via map_ptr() starting at "offset"
+ */
+void send_token(int f,int token,char *buf,int offset,int n)
+{
+  if (!do_compression) {
+    simple_send_token(f,token,buf,offset,n);
+    return;
+  }
+
+  /* compressed transmit here */
+}
+
+
+/*
+ * receive a token or buffer from the other end. If the reurn value is >0 then
+ * it is a data buffer of that length, and *data will point at the data.
+ * if the return value is -i then it represents token i-1
+ * if the return value is 0 then the end has been reached
+ */
+int recv_token(int f,char **data)
+{
+  if (!do_compression) {
+    return simple_recv_token(f,data);
+  }
+
+  /* compressed receive here */
+  return 0;
+}