added "created dir" message
authorAndrew Tridgell <tridge@samba.org>
Tue, 25 Jun 1996 07:32:03 +0000 (07:32 +0000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 25 Jun 1996 07:32:03 +0000 (07:32 +0000)
added read buffer

configure.in
main.c
match.c
rsync.c
rsync.h
util.c
version.h

index 9a04b26..1d95fb8 100644 (file)
@@ -12,7 +12,8 @@ AC_HEADER_STDC
 AC_HEADER_TIME
 AC_HEADER_SYS_WAIT
 AC_CHECK_HEADERS(sys/fcntl.h fcntl.h sys/time.h unistd.h utime.h grp.h)
-AC_CHECK_HEADERS(compat.h sys/param.h ctype.h sys/wait.h)
+AC_CHECK_HEADERS(compat.h sys/param.h ctype.h sys/wait.h sys/ioctl.h)
+AC_CHECK_HEADERS(sys/filio.h)
 
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(long)
@@ -37,7 +38,8 @@ AC_FUNC_MEMCMP
 AC_FUNC_MMAP
 AC_FUNC_UTIME_NULL
 AC_CHECK_FUNCS(waitpid strtok pipe getcwd mkdir strdup strerror chown chmod mknod)
-AC_CHECK_FUNCS(fchmod fstat strchr bcopy bzero readlink utime utimes getopt_long)
+AC_CHECK_FUNCS(fchmod fstat strchr bcopy bzero readlink utime utimes)
+AC_CHECK_FUNCS(memmove getopt_long)
 
 echo -n "checking for working fnmatch... "
 AC_TRY_RUN([#include <fnmatch.h>
diff --git a/main.c b/main.c
index 4a2079d..a2733e6 100644 (file)
--- a/main.c
+++ b/main.c
@@ -235,6 +235,8 @@ static char *get_local_name(struct file_list *flist,char *name)
   if (mkdir(name,0777) != 0) {
     fprintf(stderr,"mkdir %s : %s\n",name,strerror(errno));
     exit(1);
+  } else {
+    fprintf(am_server?stderr:stdout,"created directory %s\n",name);
   }
 
   if (chdir(name) != 0) {
diff --git a/match.c b/match.c
index 1591fdc..3b205bf 100644 (file)
--- a/match.c
+++ b/match.c
@@ -38,6 +38,9 @@ static int total_matches=0;
 static int total_data_transfer=0;
 
 
+static int check_f_in;
+
+
 struct target {
   tag t;
   int i;
@@ -97,6 +100,7 @@ static void matched(int f,struct sum_struct *s,char *buf,off_t len,int offset,in
              (int)offset,(int)last_match,i,(int)s->sums[i].len,n);
 
   if (n > 0) {
+    read_check(check_f_in);
     write_int(f,n);
     write_buf(f,buf+last_match,n);
     data_transfer += n;
@@ -197,7 +201,7 @@ static void hash_search(int f,struct sum_struct *s,char *buf,off_t len)
 }
 
 
-void match_sums(int f,struct sum_struct *s,char *buf,off_t len)
+void match_sums(int f,struct sum_struct *s,char *buf,off_t len,int f_in)
 {
   last_match = 0;
   false_alarms = 0;
@@ -205,6 +209,8 @@ void match_sums(int f,struct sum_struct *s,char *buf,off_t len)
   matches=0;
   data_transfer=0;
 
+  check_f_in = f_in;
+
   if (len > 0 && s->count>0) {
     build_hash_table(s);
 
diff --git a/rsync.c b/rsync.c
index b865353..d9b7e61 100644 (file)
--- a/rsync.c
+++ b/rsync.c
@@ -613,6 +613,8 @@ off_t send_files(struct file_list *flist,int f_out,int f_in)
 
   while (1) 
     {
+      read_check(f_in);
+
       i = read_int(f_in);
       if (i == -1) break;
 
@@ -678,7 +680,7 @@ off_t send_files(struct file_list *flist,int f_out,int f_in)
       if (!am_server && verbose)
        printf("%s\n",fname);
       
-      match_sums(f_out,s,buf,st.st_size);
+      match_sums(f_out,s,buf,st.st_size,f_in);
       write_flush(f_out);
       
       unmap_file(buf,st.st_size);
diff --git a/rsync.h b/rsync.h
index a741277..ae43046 100644 (file)
--- a/rsync.h
+++ b/rsync.h
 
 #include <sys/stat.h>
 
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+
+#ifdef HAVE_SYS_FILIO_H
+#include <sys/filio.h>
+#endif
+
 #include <signal.h>
 #ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
diff --git a/util.c b/util.c
index 4da0931..1c73394 100644 (file)
--- a/util.c
+++ b/util.c
@@ -59,19 +59,73 @@ void write_buf(int f,char *buf,int len)
   total_written += len;
 }
 
+static int num_waiting(int fd)
+{
+  int len=0;
+#ifdef FIONREAD
+  ioctl(fd,FIONREAD,&len);
+#endif
+  return(len);
+}
+
+static char *read_buffer = NULL;
+static char *read_buffer_p = NULL;
+static int read_buffer_len = 0;
+static int read_buffer_size = 0;
+
+
 void write_flush(int f)
 {
 }
 
+void read_check(int f)
+{
+  int n;
+
+  if (read_buffer_len == 0) {
+    read_buffer_p = read_buffer;
+  }
+
+  if ((n=num_waiting(f)) <= 0)
+    return;
+
+  if (read_buffer_p != read_buffer) {
+    memmove(read_buffer,read_buffer_p,read_buffer_len);
+    read_buffer_p = read_buffer;
+  }
+
+  if (n > (read_buffer_size - read_buffer_len)) {
+    read_buffer_size += n;
+    if (!read_buffer)
+      read_buffer = (char *)malloc(read_buffer_size);
+    else
+      read_buffer = (char *)realloc(read_buffer,read_buffer_size);
+    if (!read_buffer) out_of_memory("read check");      
+    read_buffer_p = read_buffer;      
+  }
+
+  n = read(f,read_buffer+read_buffer_len,n);
+  if (n > 0) {
+    read_buffer_len += n;
+  }
+}
+
 
-int readfd(int fd,char *buffer,int N)
+static int readfd(int fd,char *buffer,int N)
 {
   int  ret;
   int total=0;  
  
   while (total < N)
     {
-      ret = read(fd,buffer + total,N - total);
+      if (read_buffer_len > 0) {
+       ret = MIN(read_buffer_len,N-total);
+       memcpy(buffer+total,read_buffer_p,ret);
+       read_buffer_p += ret;
+       read_buffer_len -= ret;
+      } else {
+       ret = read(fd,buffer + total,N - total);
+      }
 
       if (ret <= 0)
        return total;
@@ -227,3 +281,4 @@ int set_modtime(char *fname,time_t modtime)
   return utimes(fname,t);
 #endif
 }
+
index 0b4f74c..1fc901b 100644 (file)
--- a/version.h
+++ b/version.h
@@ -1 +1 @@
-#define VERSION "1.0"
+#define VERSION "1.1"