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)
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);
}
--- /dev/null
+/*
+ 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;
+}