X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/56014c8c0ab087e42e227f29f9c53fcdc07d2b03..e0ed4e4087ebeff0b0fe8f3419bcccf84fbd89a9:/io.c diff --git a/io.c b/io.c index f6302fc2..3ca13df5 100644 --- a/io.c +++ b/io.c @@ -91,7 +91,7 @@ static void check_timeout(void) time_t t; err_list_push(); - + if (!io_timeout) return; if (!last_io) { @@ -137,8 +137,8 @@ static void read_error_fd(void) while (len) { n = len; - if (n > (sizeof(buf)-1)) - n = sizeof(buf)-1; + if (n > (sizeof buf - 1)) + n = sizeof buf - 1; read_loop(fd, buf, n); rwrite((enum logcode)tag, buf, n); len -= n; @@ -176,28 +176,28 @@ void io_set_filesfrom_fds(int f_in, int f_out) * program where that is a problem (start_socket_client), * kludge_around_eof is True and we just exit. */ -static void whine_about_eof (void) +static void whine_about_eof(void) { if (kludge_around_eof) - exit_cleanup (0); + exit_cleanup(0); else { - rprintf (FERROR, - "%s: connection unexpectedly closed " - "(%.0f bytes read so far)\n", - RSYNC_NAME, (double)stats.total_read); - - exit_cleanup (RERR_STREAMIO); + rprintf(FERROR, + "%s: connection unexpectedly closed " + "(%.0f bytes read so far)\n", + RSYNC_NAME, (double)stats.total_read); + + exit_cleanup(RERR_STREAMIO); } } -static void die_from_readerr (int err) +static void die_from_readerr(int err) { /* this prevents us trying to write errors on a dead socket */ io_multiplexing_close(); - + rprintf(FERROR, "%s: read error: %s\n", - RSYNC_NAME, strerror (err)); + RSYNC_NAME, strerror(err)); exit_cleanup(RERR_STREAMIO); } @@ -213,7 +213,7 @@ static void die_from_readerr (int err) * give a better explanation. We can tell whether the connection has * started by looking e.g. at whether the remote version is known yet. */ -static int read_timeout (int fd, char *buf, size_t len) +static int read_timeout(int fd, char *buf, size_t len) { int n, ret=0; @@ -351,14 +351,13 @@ static int read_timeout (int fd, char *buf, size_t len) last_io = time(NULL); continue; } else if (n == 0) { - whine_about_eof (); + whine_about_eof(); return -1; /* doesn't return */ } else if (n == -1) { if (errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN) continue; - else - die_from_readerr (errno); + die_from_readerr(errno); } } @@ -376,8 +375,7 @@ int read_filesfrom_line(int fd, char *fname) extern int io_timeout; extern int eol_nulls; extern char *remote_filesfrom_file; - extern int am_server; - int reading_remotely = remote_filesfrom_file || (am_server && fd == 0); + int reading_remotely = remote_filesfrom_file != NULL; int nulls = eol_nulls || reading_remotely; start: @@ -421,7 +419,7 @@ int read_filesfrom_line(int fd, char *fname) * Continue trying to read len bytes - don't return until len has been * read. **/ -static void read_loop (int fd, char *buf, size_t len) +static void read_loop(int fd, char *buf, size_t len) { while (len) { int n = read_timeout(fd, buf, len); @@ -472,9 +470,9 @@ static int read_unbuffered(int fd, char *buf, size_t len) exit_cleanup(RERR_STREAMIO); } - if (remaining > sizeof(line) - 1) { - rprintf(FERROR, "multiplexing overflow %d\n\n", - remaining); + if (remaining > sizeof line - 1) { + rprintf(FERROR, "multiplexing overflow %ld\n\n", + (long)remaining); exit_cleanup(RERR_STREAMIO); } @@ -495,15 +493,15 @@ static int read_unbuffered(int fd, char *buf, size_t len) * have been read. If all @p n can't be read then exit with an * error. **/ -static void readfd (int fd, char *buffer, size_t N) +static void readfd(int fd, char *buffer, size_t N) { int ret; size_t total=0; - + while (total < N) { io_flush(); - ret = read_unbuffered (fd, buffer + total, N-total); + ret = read_unbuffered(fd, buffer + total, N-total); total += ret; } @@ -524,7 +522,6 @@ int32 read_int(int f) int64 read_longint(int f) { - extern int remote_version; int64 ret; char b[8]; ret = read_int(f); @@ -537,10 +534,8 @@ int64 read_longint(int f) rprintf(FERROR,"Integer overflow - attempted 64 bit offset\n"); exit_cleanup(RERR_UNSUPPORTED); #else - if (remote_version >= 16) { - readfd(f,b,8); - ret = IVAL(b,0) | (((int64)IVAL(b,4))<<32); - } + readfd(f,b,8); + ret = IVAL(b,0) | (((int64)IVAL(b,4))<<32); #endif return ret; @@ -553,14 +548,14 @@ void read_buf(int f,char *buf,size_t len) void read_sbuf(int f,char *buf,size_t len) { - read_buf (f,buf,len); + read_buf(f,buf,len); buf[len] = 0; } unsigned char read_byte(int f) { unsigned char c; - read_buf (f, (char *)&c, 1); + read_buf(f, (char *)&c, 1); return c; } @@ -583,7 +578,7 @@ static void sleep_for_bwlimit(int bytes_written) assert(bytes_written > 0); assert(bwlimit > 0); - + tv.tv_usec = bytes_written * 1000 / bwlimit; tv.tv_sec = tv.tv_usec / 1000000; tv.tv_usec = tv.tv_usec % 1000000; @@ -692,7 +687,7 @@ void io_start_buffering(int fd) { if (io_buffer) return; multiplex_out_fd = fd; - io_buffer = (char *)malloc(IO_BUFFER_SIZE); + io_buffer = new_array(char, IO_BUFFER_SIZE); if (!io_buffer) out_of_memory("writefd"); io_buffer_count = 0; } @@ -708,8 +703,8 @@ static void mplex_write(int fd, enum logcode code, char *buf, size_t len) SIVAL(buffer, 0, ((MPLEX_BASE + (int)code)<<24) + len); - if (n > (sizeof(buffer)-4)) { - n = sizeof(buffer)-4; + if (n > (sizeof buffer - 4)) { + n = sizeof buffer - 4; } memcpy(&buffer[4], buf, n); @@ -769,7 +764,7 @@ static void writefd(int fd,char *buf,size_t len) len -= n; io_buffer_count += n; } - + if (io_buffer_count == IO_BUFFER_SIZE) io_flush(); } } @@ -797,10 +792,9 @@ void write_int_named(int f, int32 x, const char *phase) */ void write_longint(int f, int64 x) { - extern int remote_version; char b[8]; - if (remote_version < 16 || x <= 0x7FFFFFFF) { + if (x <= 0x7FFFFFFF) { write_int(f, (int)x); return; } @@ -872,9 +866,9 @@ void io_printf(int fd, const char *format, ...) va_list ap; char buf[1024]; int len; - + va_start(ap, format); - len = vsnprintf(buf, sizeof(buf), format, ap); + len = vsnprintf(buf, sizeof buf, format, ap); va_end(ap); if (len < 0) exit_cleanup(RERR_STREAMIO);