From 94481d9113220ded7ee6a76a96fa468c79680478 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 25 Jun 1996 07:32:03 +0000 Subject: [PATCH] added "created dir" message added read buffer --- configure.in | 6 ++++-- main.c | 2 ++ match.c | 8 ++++++- rsync.c | 4 +++- rsync.h | 8 +++++++ util.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-- version.h | 2 +- 7 files changed, 82 insertions(+), 7 deletions(-) diff --git a/configure.in b/configure.in index 9a04b264..1d95fb8f 100644 --- a/configure.in +++ b/configure.in @@ -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 diff --git a/main.c b/main.c index 4a2079df..a2733e64 100644 --- 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 1591fdc6..3b205bfb 100644 --- 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 b8653535..d9b7e617 100644 --- 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 a741277c..ae430468 100644 --- a/rsync.h +++ b/rsync.h @@ -75,6 +75,14 @@ #include +#ifdef HAVE_SYS_IOCTL_H +#include +#endif + +#ifdef HAVE_SYS_FILIO_H +#include +#endif + #include #ifdef HAVE_SYS_WAIT_H #include diff --git a/util.c b/util.c index 4da0931a..1c733940 100644 --- 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 } + diff --git a/version.h b/version.h index 0b4f74c7..1fc901ba 100644 --- a/version.h +++ b/version.h @@ -1 +1 @@ -#define VERSION "1.0" +#define VERSION "1.1" -- 2.34.1