+ struct redo_list *next;
+ int num;
+
+ while (!redo_list_head)
+ read_msg_fd();
+
+ num = redo_list_head->num;
+ next = redo_list_head->next;
+ free(redo_list_head);
+ redo_list_head = next;
+ if (!next)
+ redo_list_tail = NULL;
+
+ return num;
+}
+
+/**
+ * When we're the receiver and we have a local --files-from list of names
+ * that needs to be sent over the socket to the sender, we have to do two
+ * things at the same time: send the sender a list of what files we're
+ * processing and read the incoming file+info list from the sender. We do
+ * this by augmenting the read_timeout() function to copy this data. It
+ * uses the io_filesfrom_buf to read a block of data from f_in (when it is
+ * ready, since it might be a pipe) and then blast it out f_out (when it
+ * is ready to receive more data).
+ */
+void io_set_filesfrom_fds(int f_in, int f_out)
+{
+ io_filesfrom_f_in = f_in;
+ io_filesfrom_f_out = f_out;
+ io_filesfrom_bp = io_filesfrom_buf;
+ io_filesfrom_lastchar = '\0';
+ io_filesfrom_buflen = 0;
+}
+
+/**
+ * It's almost always an error to get an EOF when we're trying to read
+ * from the network, because the protocol is self-terminating.
+ *
+ * However, there is one unfortunate cases where it is not, which is
+ * rsync <2.4.6 sending a list of modules on a server, since the list
+ * is terminated by closing the socket. So, for the section of the
+ * program where that is a problem (start_socket_client),
+ * kludge_around_eof is True and we just exit.
+ */
+static void whine_about_eof(void)
+{
+ if (kludge_around_eof)
+ exit_cleanup(0);
+
+ rprintf(FERROR, RSYNC_NAME ": connection unexpectedly closed "
+ "(%.0f bytes read so far)\n",
+ (double)stats.total_read);
+
+ exit_cleanup(RERR_STREAMIO);
+}
+
+
+static void die_from_readerr(int err)
+{
+ /* this prevents us trying to write errors on a dead socket */
+ io_multiplexing_close();
+
+ rsyserr(FERROR, err, "read error");
+ exit_cleanup(RERR_STREAMIO);
+}
+
+
+/**
+ * Read from a socket with I/O 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. 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)
+{
+ int n, ret = 0;