X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/20caffd2b361bcad51692998411e4cc566c04b40..d8a7290f8621b72139461ed6606cde31fa4d544f:/io.c diff --git a/io.c b/io.c index 7c50d5af..3ece9c3b 100644 --- a/io.c +++ b/io.c @@ -378,7 +378,7 @@ static void forward_filesfrom_data(void) } if (len) { char *f = x.buf + x.pos; - char *t = f; /* Keep any non-zero offset to avoid iconv reset. */ + char *t = x.buf; char *eob = f + len; /* Eliminate any multi-'\0' runs. */ while (f != eob) { @@ -393,7 +393,7 @@ static void forward_filesfrom_data(void) if (filesfrom_convert) { /* TODO would it help to translate each string between nulls separately? */ x.len = len; - iconvbufs(ic_send, &x, &iobuf.out, ICB_INCLUDE_BAD|ICB_INCLUDE_INCOMPLETE|ICB_CIRCULAR_OUT); + iconvbufs(ic_send, &x, &iobuf.out, ICB_INCLUDE_BAD|ICB_INCLUDE_INCOMPLETE|ICB_CIRCULAR_OUT|ICB_INIT); } else #endif if (len) { @@ -471,8 +471,8 @@ static char *perform_io(size_t needed, int flags) if (!(iobuf.in.buf = realloc_array(iobuf.in.buf, char, needed))) out_of_memory("perform_io"); if (DEBUG_GTE(IO, 4)) { - rprintf(FINFO, "[%s] resized input buffer from %d to %d bytes.\n", - who_am_i(), iobuf.in.size, needed); + rprintf(FINFO, "[%s] resized input buffer from %ld to %ld bytes.\n", + who_am_i(), (long)iobuf.in.size, (long)needed); } iobuf.in.size = needed; } @@ -482,8 +482,8 @@ static char *perform_io(size_t needed, int flags) memmove(iobuf.in.buf, iobuf.in.buf + iobuf.in.pos, iobuf.in.len); if (DEBUG_GTE(IO, 4)) { rprintf(FINFO, - "[%s] moved %d bytes from %d to 0 in the input buffer (size=%d, needed=%d).\n", - who_am_i(), iobuf.in.len, iobuf.in.pos, iobuf.in.size, needed); + "[%s] moved %ld bytes from %ld to 0 in the input buffer (size=%ld, needed=%ld).\n", + who_am_i(), (long)iobuf.in.len, (long)iobuf.in.pos, (long)iobuf.in.size, (long)needed); } if (iobuf.raw_input_ends_before) iobuf.raw_input_ends_before -= iobuf.in.pos; @@ -803,7 +803,7 @@ int send_msg(enum msgcode code, const char *buf, size_t len, int convert) len = iobuf.msg.len; iconvbufs(ic_send, &inbuf, &iobuf.msg, - ICB_INCLUDE_BAD | ICB_INCLUDE_INCOMPLETE | ICB_CIRCULAR_OUT); + ICB_INCLUDE_BAD | ICB_INCLUDE_INCOMPLETE | ICB_CIRCULAR_OUT | ICB_INIT); if (inbuf.len > 0) { rprintf(FERROR, "overflowed iobuf.msg buffer in send_msg"); exit_cleanup(RERR_UNSUPPORTED); @@ -1039,7 +1039,7 @@ int read_line(int fd, char *buf, size_t bufsiz, int flags) iconv_buf.pos = 0; iconv_buf.len = s - iconv_buf.buf; iconvbufs(ic_recv, &iconv_buf, &outbuf, - ICB_INCLUDE_BAD | ICB_INCLUDE_INCOMPLETE); + ICB_INCLUDE_BAD | ICB_INCLUDE_INCOMPLETE | ICB_INIT); outbuf.buf[outbuf.len] = '\0'; return outbuf.len; } @@ -1197,7 +1197,8 @@ void io_end_buffering_out(BOOL free_buffers) void maybe_flush_socket(int important) { - if (iobuf.out.buf && iobuf.out.len && (important || time(NULL) - last_io_out >= 5)) + if (flist_eof && iobuf.out.buf && iobuf.out.len > iobuf.out_empty_len + && (important || time(NULL) - last_io_out >= 5)) io_flush(NORMAL_FLUSH); } @@ -1300,13 +1301,14 @@ static void read_a_msg(void) INIT_XBUF(inbuf, ibuf, 0, (size_t)-1); while (msg_bytes) { + inbuf.pos = 0; inbuf.len = msg_bytes > sizeof ibuf ? sizeof ibuf : msg_bytes; memcpy(inbuf.buf, perform_io(inbuf.len, PIO_INPUT_AND_CONSUME), inbuf.len); if (!(msg_bytes -= inbuf.len) && !ibuf[inbuf.len-1]) inbuf.len--, add_null = 1; if (iconvbufs(ic_send, &inbuf, &outbuf, - ICB_INCLUDE_BAD | ICB_INCLUDE_INCOMPLETE) < 0) + ICB_INCLUDE_BAD | ICB_INCLUDE_INCOMPLETE | ICB_INIT) < 0) goto overflow; } if (add_null) {