+/* setup the fd used to propogate errors */
+void io_set_error_fd(int fd)
+{
+ io_error_fd = fd;
+}
+
+/* read some data from the error fd and write it to the write log code */
+static void read_error_fd(void)
+{
+ char buf[200];
+ int n;
+ int fd = io_error_fd;
+ int tag, len;
+
+ /* io_error_fd is temporarily disabled -- is this meant to
+ * prevent indefinite recursion? */
+ io_error_fd = -1;
+
+ read_loop(fd, buf, 4);
+ tag = IVAL(buf, 0);
+
+ len = tag & 0xFFFFFF;
+ tag = tag >> 24;
+ tag -= MPLEX_BASE;
+
+ while (len) {
+ n = len;
+ if (n > (sizeof(buf)-1)) n = sizeof(buf)-1;
+ read_loop(fd, buf, n);
+ rwrite((enum logcode)tag, buf, n);
+ len -= n;
+ }
+
+ io_error_fd = fd;
+}
+
+
+static void whine_about_eof (void)
+{
+ /**
+ 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.
+ */
+
+ if (kludge_around_eof)
+ 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);
+ }
+}
+
+
+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));
+ exit_cleanup(RERR_STREAMIO);
+}