1 This patch extends the current keep-alive code (which currently only
2 handles silences in the generator's output) to deal with potential
3 silences in the sender's output when it is reading a lot of checksum
4 data from the generator (caused by the transfer of a large file).
6 After applying this patch, run "make proto".
8 --- orig/clientserver.c 2005-04-09 17:38:31
9 +++ clientserver.c 2005-05-16 01:02:41
10 @@ -40,8 +40,6 @@ extern int sanitize_paths;
11 extern int filesfrom_fd;
12 extern int remote_protocol;
13 extern int protocol_version;
14 -extern int io_timeout;
15 -extern int select_timeout;
16 extern int orig_umask;
18 extern int default_af_hint;
19 @@ -518,11 +516,8 @@ static int rsync_module(int f_in, int f_
20 exit_cleanup(RERR_UNSUPPORTED);
23 - if (lp_timeout(i)) {
24 - io_timeout = lp_timeout(i);
25 - if (io_timeout < select_timeout)
26 - select_timeout = io_timeout;
29 + set_io_timeout(lp_timeout(i));
31 start_server(f_in, f_out, argc, argp);
33 --- orig/generator.c 2005-05-14 19:51:15
34 +++ generator.c 2005-05-16 01:02:43
35 @@ -59,8 +59,8 @@ extern int csum_length;
36 extern int ignore_times;
38 extern OFF_T max_size;
39 -extern int io_timeout;
41 +extern int allowed_lull;
42 extern int sock_f_out;
43 extern int ignore_timeout;
44 extern int protocol_version;
45 @@ -89,8 +89,6 @@ extern int backup_suffix_len;
46 extern struct file_list *the_file_list;
47 extern struct filter_list_struct server_filter_list;
49 -int allowed_lull = 0;
51 static int deletion_count = 0; /* used to implement --max-delete */
54 @@ -1145,10 +1143,11 @@ notify_others:
56 void generate_files(int f_out, struct file_list *flist, char *local_name)
60 char fbuf[MAXPATHLEN];
61 int itemizing, maybe_PERMS_REPORT;
63 + int lull_mod = allowed_lull * 5;
64 int need_retouch_dir_times = preserve_times && !omit_dir_times;
65 int need_retouch_dir_perms = 0;
66 int save_only_existing = only_existing;
67 @@ -1156,9 +1155,6 @@ void generate_files(int f_out, struct fi
68 int save_do_progress = do_progress;
69 int save_make_backups = make_backups;
71 - allowed_lull = read_batch ? 0 : (io_timeout + 1) / 2;
72 - lull_mod = allowed_lull * 5;
74 if (protocol_version >= 29) {
76 maybe_PERMS_REPORT = log_format_has_i ? 0 : PERMS_REPORT;
77 --- orig/io.c 2005-05-12 17:42:08
78 +++ io.c 2005-05-18 23:19:18
81 extern size_t bwlimit_writemax;
83 -extern int io_timeout;
84 extern int allowed_lull;
88 extern int am_generator;
90 +extern int read_batch;
91 extern int csum_length;
92 extern int checksum_seed;
93 extern int protocol_version;
94 @@ -59,7 +59,6 @@ extern struct stats stats;
95 extern struct file_list *the_file_list;
97 const char phase_unknown[] = "unknown";
98 -int select_timeout = SELECT_TIMEOUT;
99 int ignore_timeout = 0;
101 int batch_gen_fd = -1;
102 @@ -90,7 +89,8 @@ int sock_f_out = -1;
104 static int io_multiplexing_out;
105 static int io_multiplexing_in;
106 -static time_t last_io;
107 +static time_t last_in_io;
108 +static time_t last_out_io;
111 static int write_batch_monitor_in = -1;
112 @@ -103,6 +103,8 @@ static char *io_filesfrom_bp;
113 static char io_filesfrom_lastchar;
114 static int io_filesfrom_buflen;
115 static size_t contiguous_write_len = 0;
116 +static int io_timeout;
117 +static int select_timeout = SELECT_TIMEOUT;
119 static void read_loop(int fd, char *buf, size_t len);
121 @@ -166,17 +168,17 @@ static void check_timeout(void)
122 if (!io_timeout || ignore_timeout)
126 - last_io = time(NULL);
128 + last_in_io = time(NULL);
134 - if (t - last_io >= io_timeout) {
135 + if (t - last_in_io >= io_timeout) {
136 if (!am_server && !am_daemon) {
137 rprintf(FERROR, "io timeout after %d seconds -- exiting\n",
139 + (int)(t-last_in_io));
141 exit_cleanup(RERR_TIMEOUT);
143 @@ -190,6 +192,18 @@ void io_set_sock_fds(int f_in, int f_out
147 +void set_io_timeout(int secs)
151 + if (!io_timeout || io_timeout > SELECT_TIMEOUT)
152 + select_timeout = SELECT_TIMEOUT;
154 + select_timeout = io_timeout;
156 + allowed_lull = read_batch ? 0 : (io_timeout + 1) / 2;
159 /* Setup the fd used to receive MSG_* messages. Only needed during the
160 * early stages of being a local sender (up through the sending of the
161 * file list) or when we're the generator (to fetch the messages from
162 @@ -574,8 +588,8 @@ static int read_timeout(int fd, char *bu
166 - if (fd == sock_f_in && (io_timeout || am_generator))
167 - last_io = time(NULL);
168 + if (fd == sock_f_in && io_timeout)
169 + last_in_io = time(NULL);
173 @@ -667,14 +681,14 @@ void io_end_buffering(void)
175 void maybe_flush_socket(void)
177 - if (iobuf_out && iobuf_out_cnt && time(NULL) - last_io >= 5)
178 + if (iobuf_out && iobuf_out_cnt && time(NULL) - last_out_io >= 5)
179 io_flush(NORMAL_FLUSH);
183 void maybe_send_keepalive(void)
185 - if (time(NULL) - last_io >= allowed_lull) {
186 + if (time(NULL) - last_out_io >= allowed_lull) {
187 if (!iobuf_out || !iobuf_out_cnt) {
188 if (protocol_version < 29)
189 return; /* there's nothing we can do */
190 @@ -1077,7 +1091,7 @@ static void writefd_unbuffered(int fd,ch
191 /* If the other side is sending us error messages, try
192 * to grab any messages they sent before they died. */
193 while (fd == sock_f_out && io_multiplexing_in) {
194 - io_timeout = select_timeout = 30;
195 + set_io_timeout(30);
197 readfd_unbuffered(sock_f_in, io_filesfrom_buf,
198 sizeof io_filesfrom_buf);
199 @@ -1089,7 +1103,7 @@ static void writefd_unbuffered(int fd,ch
201 if (fd == sock_f_out) {
202 if (io_timeout || am_generator)
203 - last_io = time(NULL);
204 + last_out_io = time(NULL);
205 sleep_for_bwlimit(ret);
208 --- orig/options.c 2005-05-10 15:32:58
209 +++ options.c 2005-05-16 01:02:43
212 extern int module_id;
213 extern int sanitize_paths;
214 -extern int select_timeout;
215 extern struct filter_list_struct filter_list;
216 extern struct filter_list_struct server_filter_list;
218 @@ -75,7 +74,7 @@ int relative_paths = -1;
219 int implied_dirs = 1;
221 int force_delete = 0;
223 +int allowed_lull = 0;
224 char *files_from = NULL;
225 int filesfrom_fd = -1;
226 char *filesfrom_host = NULL;
227 @@ -161,6 +160,7 @@ int list_only = 0;
228 char *batch_name = NULL;
230 static int daemon_opt; /* sets am_daemon after option error-reporting */
231 +static int timeout_val;
232 static int F_option_cnt = 0;
233 static int modify_window_set;
234 static int itemize_changes = 0;
235 @@ -363,8 +363,7 @@ void usage(enum logcode F)
236 enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
237 OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST,
238 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
239 - OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH,
240 - OPT_TIMEOUT, OPT_MAX_SIZE,
241 + OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
242 OPT_REFUSED_BASE = 9000};
244 static struct poptOption long_options[] = {
245 @@ -428,7 +427,7 @@ static struct poptOption long_options[]
246 {"block-size", 'B', POPT_ARG_LONG, &block_size, 0, 0, 0 },
247 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
248 {"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 },
249 - {"timeout", 0, POPT_ARG_INT, &io_timeout, OPT_TIMEOUT, 0, 0 },
250 + {"timeout", 0, POPT_ARG_INT, &timeout_val, 0, 0, 0 },
251 {"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
252 {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
253 {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
254 @@ -844,11 +843,6 @@ int parse_arguments(int *argc, const cha
259 - if (io_timeout && io_timeout < select_timeout)
260 - select_timeout = io_timeout;
266 @@ -1115,6 +1109,8 @@ int parse_arguments(int *argc, const cha
270 + set_io_timeout(timeout_val);
272 if (verbose && !log_format) {
274 log_before_transfer = !am_server;
275 @@ -1357,8 +1353,8 @@ void server_options(char **args,int *arg
276 args[ac++] = max_size_arg;
280 - if (asprintf(&arg, "--timeout=%d", io_timeout) < 0)
282 + if (asprintf(&arg, "--timeout=%d", timeout_val) < 0)
286 --- orig/sender.c 2005-04-14 01:53:12
287 +++ sender.c 2005-05-16 01:02:44
288 @@ -28,6 +28,7 @@ extern int log_format_has_i;
289 extern int daemon_log_format_has_i;
290 extern int csum_length;
292 +extern int allowed_lull;
293 extern int protocol_version;
294 extern int remove_sent_files;
295 extern int updating_basis_file;
296 @@ -56,6 +57,7 @@ static struct sum_struct *receive_sums(i
298 struct sum_struct *s;
300 + int lull_mod = allowed_lull * 5;
303 if (!(s = new(struct sum_struct)))
304 @@ -89,6 +91,9 @@ static struct sum_struct *receive_sums(i
305 s->sums[i].len = s->blength;
306 offset += s->sums[i].len;
308 + if (allowed_lull && !(i % lull_mod))
309 + maybe_send_keepalive();
313 "chunk[%d] len=%d offset=%.0f sum1=%08x\n",