X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/ae682c3e115aae1e15811e1411f5e7e3438d3193..c3563c46ed40c3021b61f5ed228c9eca2d64e1f3:/io.c diff --git a/io.c b/io.c index b469d8be..39996885 100644 --- a/io.c +++ b/io.c @@ -1,5 +1,6 @@ -/* - Copyright (C) Andrew Tridgell 1996 +/* -*- c-file-style: "linux" -*- + + Copyright (C) 1996-2000 by Andrew Tridgell Copyright (C) Paul Mackerras 1996 This program is free software; you can redistribute it and/or modify @@ -103,9 +104,15 @@ static void read_error_fd(void) static int no_flush; -/* read from a socket with IO timeout. return the number of - bytes read. If no bytes can be read then exit, never return - a number <= 0 */ +/* + * Read from a socket with IO timeout. return the number of bytes + * read. If no bytes can be read then exit, never return a number <= 0. + * + * TODO: If the remote shell connection fails, then current versions actually + * report an "unexpected EOF" error here. Since it's a fairly common mistake + * to try to use rsh when ssh is required, we should trap that: if we fail + * to read any data at all, we should give a better explanation. + */ static int read_timeout(int fd, char *buf, int len) { int n, ret=0; @@ -372,6 +379,7 @@ static void writefd_unbuffered(int fd,char *buf,int len) if (ret == -1 && (errno == EWOULDBLOCK || errno == EAGAIN)) { + msleep(1); continue; } @@ -454,6 +462,8 @@ void io_flush(void) io_buffer_count = 0; } + +/* XXX: fd is ignored, which seems a little strange. */ void io_end_buffering(int fd) { io_flush(); @@ -463,6 +473,17 @@ void io_end_buffering(int fd) } } +/* some OSes have a bug where an exit causes the pending writes on + a socket to be flushed. Do an explicit shutdown to try to prevent this */ +void io_shutdown(void) +{ + if (multiplex_out_fd != -1) close(multiplex_out_fd); + if (io_error_fd != -1) close(io_error_fd); + multiplex_out_fd = -1; + io_error_fd = -1; +} + + static void writefd(int fd,char *buf,int len) { stats.total_written += len; @@ -493,6 +514,11 @@ void write_int(int f,int32 x) writefd(f,b,4); } + +/* + * Note: int64 may actually be a 32-bit type if ./configure couldn't find any + * 64-bit types on this platform. + */ void write_longint(int f, int64 x) { extern int remote_version;