If we fail writing to the socket and we're receiving error messages
[rsync/rsync.git] / io.c
diff --git a/io.c b/io.c
index a094561..f3ea2a6 100644 (file)
--- a/io.c
+++ b/io.c
@@ -899,6 +899,13 @@ static void writefd_unbuffered(int fd,char *buf,size_t len)
                        rsyserr(FERROR, errno,
                                "writefd_unbuffered failed to write %ld bytes: phase \"%s\"",
                                (long)len, io_write_phase);
+                       /* If the other side is sending us error messages, try
+                        * to grab any messages they sent before they died. */
+                       while (fd == sock_f_out && am_sender) {
+                               io_timeout = 30;
+                               readfd_unbuffered(sock_f_in, io_filesfrom_buf,
+                                                 sizeof io_filesfrom_buf);
+                       }
                        exit_cleanup(RERR_STREAMIO);
                }
 
@@ -1130,6 +1137,8 @@ void io_multiplexing_close(void)
 
 void start_write_batch(int fd)
 {
+       write_stream_flags(batch_fd);
+
        /* Some communication has already taken place, but we don't
         * enable batch writing until here so that we can write a
         * canonical record of the communication even though the