+extern int am_server;
+extern int am_sender;
+extern int am_receiver;
+extern int am_generator;
+extern int msgs2stderr;
+extern int inc_recurse;
+extern int io_error;
+extern int eol_nulls;
+extern int flist_eof;
+extern int file_total;
+extern int file_old_total;
+extern int list_only;
+extern int read_batch;
+extern int compat_flags;
+extern int protect_args;
+extern int checksum_seed;
+extern int protocol_version;
+extern int remove_source_files;
+extern int preserve_hard_links;
+extern BOOL extra_flist_sending_enabled;
+extern struct stats stats;
+extern struct file_list *cur_flist;
+#ifdef ICONV_OPTION
+extern int filesfrom_convert;
+extern iconv_t ic_send, ic_recv;
+#endif
+
+int csum_length = SHORT_SUM_LENGTH; /* initial value */
+int allowed_lull = 0;
+int batch_fd = -1;
+int msgdone_cnt = 0;
+int forward_flist_data = 0;
+BOOL flist_receiving_enabled = False;
+
+/* Ignore an EOF error if non-zero. See whine_about_eof(). */
+int kluge_around_eof = 0;
+
+int sock_f_in = -1;
+int sock_f_out = -1;
+
+int64 total_data_read = 0;
+int64 total_data_written = 0;
+
+static struct {
+ xbuf in, out, msg;
+ int in_fd;
+ int out_fd; /* Both "out" and "msg" go to this fd. */
+ int in_multiplexed;
+ unsigned out_empty_len;
+ size_t raw_data_header_pos; /* in the out xbuf */
+ size_t raw_flushing_ends_before; /* in the out xbuf */
+ size_t raw_input_ends_before; /* in the in xbuf */
+} iobuf = { .in_fd = -1, .out_fd = -1 };
+
+static time_t last_io_in;
+static time_t last_io_out;
+
+static int write_batch_monitor_in = -1;
+static int write_batch_monitor_out = -1;
+
+static int ff_forward_fd = -1;
+static int ff_reenable_multiplex = -1;
+static char ff_lastchar = '\0';
+static xbuf ff_xb = EMPTY_XBUF;
+#ifdef ICONV_OPTION
+static xbuf iconv_buf = EMPTY_XBUF;
+#endif
+static int select_timeout = SELECT_TIMEOUT;
+static int active_filecnt = 0;
+static OFF_T active_bytecnt = 0;
+static int first_message = 1;
+
+static char int_byte_extra[64] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* (00 - 3F)/4 */
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* (40 - 7F)/4 */
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* (80 - BF)/4 */
+ 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6, /* (C0 - FF)/4 */
+};
+
+/* Our I/O buffers are sized with no bits on in the lowest byte of the "size"
+ * (indeed, our rounding of sizes in 1024-byte units assures more than this).
+ * This allows the code that is storing bytes near the physical end of a
+ * circular buffer to temporarily reduce the buffer's size (in order to make
+ * some storing idioms easier), while also making it simple to restore the
+ * buffer's actual size when the buffer's "pos" wraps around to the start (we
+ * just round the buffer's size up again). */
+
+#define IOBUF_WAS_REDUCED(siz) ((siz) & 0xFF)
+#define IOBUF_RESTORE_SIZE(siz) (((siz) | 0xFF) + 1)
+
+#define IN_MULTIPLEXED (iobuf.in_multiplexed != 0)
+#define IN_MULTIPLEXED_AND_READY (iobuf.in_multiplexed > 0)
+#define OUT_MULTIPLEXED (iobuf.out_empty_len != 0)
+
+#define PIO_NEED_INPUT (1<<0) /* The *_NEED_* flags are mutually exclusive. */
+#define PIO_NEED_OUTROOM (1<<1)
+#define PIO_NEED_MSGROOM (1<<2)
+
+#define PIO_CONSUME_INPUT (1<<4) /* Must becombined with PIO_NEED_INPUT. */
+
+#define PIO_INPUT_AND_CONSUME (PIO_NEED_INPUT | PIO_CONSUME_INPUT)
+#define PIO_NEED_FLAGS (PIO_NEED_INPUT | PIO_NEED_OUTROOM | PIO_NEED_MSGROOM)
+
+#define REMOTE_OPTION_ERROR "rsync: on remote machine: -"
+#define REMOTE_OPTION_ERROR2 ": unknown option"
+
+#define FILESFROM_BUFLEN 2048