+}
+
+static void check_for_d_option_error(const char *msg)
+{
+ static char rsync263_opts[] = "BCDHIKLPRSTWabceghlnopqrtuvxz";
+ char *colon;
+ int saw_d = 0;
+
+ if (*msg != 'r'
+ || strncmp(msg, REMOTE_OPTION_ERROR, sizeof REMOTE_OPTION_ERROR - 1) != 0)
+ return;
+
+ msg += sizeof REMOTE_OPTION_ERROR - 1;
+ if (*msg == '-' || (colon = strchr(msg, ':')) == NULL
+ || strncmp(colon, REMOTE_OPTION_ERROR2, sizeof REMOTE_OPTION_ERROR2 - 1) != 0)
+ return;
+
+ for ( ; *msg != ':'; msg++) {
+ if (*msg == 'd')
+ saw_d = 1;
+ else if (*msg == 'e')
+ break;
+ else if (strchr(rsync263_opts, *msg) == NULL)
+ return;
+ }
+
+ if (saw_d) {
+ rprintf(FWARNING,
+ "*** Try using \"--old-d\" if remote rsync is <= 2.6.3 ***\n");
+ }
+}
+
+/* This is used by the generator to limit how many file transfers can
+ * be active at once when --remove-source-files is specified. Without
+ * this, sender-side deletions were mostly happening at the end. */
+void increment_active_files(int ndx, int itemizing, enum logcode code)
+{
+ while (1) {
+ /* TODO: tune these limits? */
+ int limit = active_bytecnt >= 128*1024 ? 10 : 50;
+ if (active_filecnt < limit)
+ break;
+ check_for_finished_files(itemizing, code, 0);
+ if (active_filecnt < limit)
+ break;
+ if (iobuf_out_cnt)
+ io_flush(NORMAL_FLUSH);
+ else
+ read_a_msg(msg_fd_in);
+ }
+
+ active_filecnt++;
+ active_bytecnt += F_LENGTH(cur_flist->files[ndx - cur_flist->ndx_start]);
+}
+
+/* Write an message to a multiplexed stream. If this fails, rsync exits. */
+static void mplex_write(int fd, enum msgcode code, const char *buf, size_t len, int convert)
+{
+ char buffer[BIGPATHBUFLEN]; /* Oversized for use by iconv code. */
+ size_t n = len;
+
+#ifdef ICONV_OPTION
+ /* We need to convert buf before doing anything else so that we
+ * can include the (converted) byte length in the message header. */
+ if (convert && ic_send != (iconv_t)-1) {
+ xbuf outbuf, inbuf;
+
+ INIT_XBUF(outbuf, buffer + 4, 0, sizeof buffer - 4);
+ INIT_XBUF(inbuf, (char*)buf, len, (size_t)-1);
+
+ iconvbufs(ic_send, &inbuf, &outbuf,
+ ICB_INCLUDE_BAD | ICB_INCLUDE_INCOMPLETE);
+ if (inbuf.len > 0) {
+ rprintf(FERROR, "overflowed conversion buffer in mplex_write");
+ exit_cleanup(RERR_UNSUPPORTED);
+ }
+
+ n = len = outbuf.len;
+ } else
+#endif
+ if (n > 1024 - 4) /* BIGPATHBUFLEN can handle 1024 bytes */
+ n = 0; /* We'd rather do 2 writes than too much memcpy(). */
+ else
+ memcpy(buffer + 4, buf, n);
+
+ SIVAL(buffer, 0, ((MPLEX_BASE + (int)code)<<24) + len);
+
+ keep_defer_forwarding++; /* defer_forwarding_messages++ on return */
+ writefd_unbuffered(fd, buffer, n+4);
+ keep_defer_forwarding--;
+
+ if (len > n)
+ writefd_unbuffered(fd, buf+n, len-n);
+
+ if (!--defer_forwarding_messages && !no_flush)
+ msg_flush();
+}
+
+int send_msg(enum msgcode code, const char *buf, int len, int convert)
+{
+ if (msg_fd_out < 0) {
+ if (!defer_forwarding_messages)
+ return io_multiplex_write(code, buf, len, convert);
+ if (!io_multiplexing_out)
+ return 0;
+ msg_list_add(&msg_queue, code, buf, len, convert);
+ return 1;
+ }
+ if (defer_forwarding_messages)
+ msg_list_add(&msg_queue, code, buf, len, convert);
+ else
+ mplex_write(msg_fd_out, code, buf, len, convert);
+ return 1;
+}