mirror of
https://github.com/RsyncProject/rsync.git
synced 2026-03-10 02:16:35 -04:00
added write buffering during the file list sending. This makes things
a bit more efficient (less system calls)
This commit is contained in:
10
flist.c
10
flist.c
@@ -573,6 +573,10 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
|
||||
flist->malloced);
|
||||
if (!flist->files) out_of_memory("send_file_list");
|
||||
|
||||
if (f != -1) {
|
||||
io_start_buffering(f);
|
||||
}
|
||||
|
||||
for (i=0;i<argc;i++) {
|
||||
char fname2[MAXPATHLEN];
|
||||
char *fname = fname2;
|
||||
@@ -658,7 +662,6 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
|
||||
|
||||
if (f != -1) {
|
||||
send_file_entry(NULL,f,0);
|
||||
write_flush(f);
|
||||
}
|
||||
|
||||
if (verbose && recurse && !am_server && f != -1)
|
||||
@@ -677,6 +680,11 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
|
||||
write_int(f, io_error);
|
||||
}
|
||||
|
||||
if (f != -1) {
|
||||
io_end_buffering(f);
|
||||
write_flush(f);
|
||||
}
|
||||
|
||||
if (verbose > 2)
|
||||
rprintf(FINFO,"send_file_list done\n");
|
||||
|
||||
|
||||
54
io.c
54
io.c
@@ -301,7 +301,7 @@ int write_file(int f,char *buf,int len)
|
||||
}
|
||||
|
||||
|
||||
static int writefd(int fd,char *buf,int len)
|
||||
static int writefd_unbuffered(int fd,char *buf,int len)
|
||||
{
|
||||
int total = 0;
|
||||
fd_set w_fds, r_fds;
|
||||
@@ -375,6 +375,58 @@ static int writefd(int fd,char *buf,int len)
|
||||
return total;
|
||||
}
|
||||
|
||||
static char *io_buffer;
|
||||
static int io_buffer_count;
|
||||
|
||||
void io_start_buffering(int fd)
|
||||
{
|
||||
io_buffer = (char *)malloc(IO_BUFFER_SIZE);
|
||||
if (!io_buffer) out_of_memory("writefd");
|
||||
io_buffer_count = 0;
|
||||
}
|
||||
|
||||
void io_end_buffering(int fd)
|
||||
{
|
||||
if (io_buffer_count) {
|
||||
if (writefd_unbuffered(fd, io_buffer,
|
||||
io_buffer_count) !=
|
||||
io_buffer_count) {
|
||||
rprintf(FERROR,"write failed\n");
|
||||
exit_cleanup(1);
|
||||
}
|
||||
io_buffer_count = 0;
|
||||
}
|
||||
free(io_buffer);
|
||||
io_buffer = NULL;
|
||||
}
|
||||
|
||||
static int writefd(int fd,char *buf,int len1)
|
||||
{
|
||||
int len = len1;
|
||||
|
||||
if (!io_buffer) return writefd_unbuffered(fd, buf, len);
|
||||
|
||||
while (len) {
|
||||
int n = MIN(len, IO_BUFFER_SIZE-io_buffer_count);
|
||||
if (n > 0) {
|
||||
memcpy(io_buffer+io_buffer_count, buf, n);
|
||||
buf += n;
|
||||
len -= n;
|
||||
io_buffer_count += n;
|
||||
}
|
||||
|
||||
if (io_buffer_count == IO_BUFFER_SIZE) {
|
||||
if (writefd_unbuffered(fd, io_buffer,
|
||||
io_buffer_count) !=
|
||||
io_buffer_count) {
|
||||
return -1;
|
||||
}
|
||||
io_buffer_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return len1;
|
||||
}
|
||||
|
||||
|
||||
void write_int(int f,int32 x)
|
||||
|
||||
Reference in New Issue
Block a user