9f15c552c3e9ac8618986bd0023b1f76e13e2b89
[rsync/rsync-patches.git] / keepalive.diff
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).
5
6 After applying this patch, run "make proto".
7
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;
17  extern int no_detach;
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);
21         }
22  
23 -       if (lp_timeout(i)) {
24 -               io_timeout = lp_timeout(i);
25 -               if (io_timeout < select_timeout)
26 -                       select_timeout = io_timeout;
27 -       }
28 +       if (lp_timeout(i))
29 +               set_io_timeout(lp_timeout(i));
30  
31         start_server(f_in, f_out, argc, argp);
32  
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;
37  extern int size_only;
38  extern OFF_T max_size;
39 -extern int io_timeout;
40  extern int io_error;
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;
48  
49 -int allowed_lull = 0;
50 -
51  static int deletion_count = 0; /* used to implement --max-delete */
52  
53  
54 @@ -1145,10 +1143,11 @@ notify_others:
55  
56  void generate_files(int f_out, struct file_list *flist, char *local_name)
57  {
58 -       int i, lull_mod;
59 +       int i;
60         char fbuf[MAXPATHLEN];
61         int itemizing, maybe_PERMS_REPORT;
62         enum logcode code;
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;
70  
71 -       allowed_lull = read_batch ? 0 : (io_timeout + 1) / 2;
72 -       lull_mod = allowed_lull * 5;
73 -
74         if (protocol_version >= 29) {
75                 itemizing = 1;
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
79 @@ -42,13 +42,13 @@
80  extern int bwlimit;
81  extern size_t bwlimit_writemax;
82  extern int verbose;
83 -extern int io_timeout;
84  extern int allowed_lull;
85  extern int am_server;
86  extern int am_daemon;
87  extern int am_sender;
88  extern int am_generator;
89  extern int eol_nulls;
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;
96  
97  const char phase_unknown[] = "unknown";
98 -int select_timeout = SELECT_TIMEOUT;
99  int ignore_timeout = 0;
100  int batch_fd = -1;
101  int batch_gen_fd = -1;
102 @@ -90,7 +89,8 @@ int sock_f_out = -1;
103  
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;
109  static int no_flush;
110  
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;
118  
119  static void read_loop(int fd, char *buf, size_t len);
120  
121 @@ -166,17 +168,17 @@ static void check_timeout(void)
122         if (!io_timeout || ignore_timeout)
123                 return;
124  
125 -       if (!last_io) {
126 -               last_io = time(NULL);
127 +       if (!last_in_io) {
128 +               last_in_io = time(NULL);
129                 return;
130         }
131  
132         t = time(NULL);
133  
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",
138 -                               (int)(t-last_io));
139 +                               (int)(t-last_in_io));
140                 }
141                 exit_cleanup(RERR_TIMEOUT);
142         }
143 @@ -190,6 +192,18 @@ void io_set_sock_fds(int f_in, int f_out
144         sock_f_out = f_out;
145  }
146  
147 +void set_io_timeout(int secs)
148 +{
149 +       io_timeout = secs;
150 +
151 +       if (!io_timeout || io_timeout > SELECT_TIMEOUT)
152 +               select_timeout = SELECT_TIMEOUT;
153 +       else
154 +               select_timeout = io_timeout;
155 +
156 +       allowed_lull = read_batch ? 0 : (io_timeout + 1) / 2;
157 +}
158 +
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
163                 len -= n;
164                 ret += n;
165  
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);
170         }
171  
172         return ret;
173 @@ -667,14 +681,14 @@ void io_end_buffering(void)
174  
175  void maybe_flush_socket(void)
176  {
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);
180  }
181  
182  
183  void maybe_send_keepalive(void)
184  {
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);
196                                 ignore_timeout = 0;
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
200  
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);
206                 }
207         }
208 --- orig/options.c      2005-05-10 15:32:58
209 +++ options.c   2005-05-16 01:02:43
210 @@ -23,7 +23,6 @@
211  
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;
217  
218 @@ -75,7 +74,7 @@ int relative_paths = -1;
219  int implied_dirs = 1;
220  int numeric_ids = 0;
221  int force_delete = 0;
222 -int io_timeout = 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;
229  
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};
243  
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
255                         }
256                         break;
257  
258 -               case OPT_TIMEOUT:
259 -                       if (io_timeout && io_timeout < select_timeout)
260 -                               select_timeout = io_timeout;
261 -                       break;
262 -
263                 case OPT_LINK_DEST:
264  #ifdef HAVE_LINK
265                         link_dest = 1;
266 @@ -1115,6 +1109,8 @@ int parse_arguments(int *argc, const cha
267         if (dry_run)
268                 do_xfers = 0;
269  
270 +       set_io_timeout(timeout_val);
271 +
272         if (verbose && !log_format) {
273                 log_format = "%n%L";
274                 log_before_transfer = !am_server;
275 @@ -1357,8 +1353,8 @@ void server_options(char **args,int *arg
276                 args[ac++] = max_size_arg;
277         }
278  
279 -       if (io_timeout) {
280 -               if (asprintf(&arg, "--timeout=%d", io_timeout) < 0)
281 +       if (timeout_val) {
282 +               if (asprintf(&arg, "--timeout=%d", timeout_val) < 0)
283                         goto oom;
284                 args[ac++] = arg;
285         }
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;
291  extern int io_error;
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
297  {
298         struct sum_struct *s;
299         int32 i;
300 +       int lull_mod = allowed_lull * 5;
301         OFF_T offset = 0;
302  
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;
307  
308 +               if (allowed_lull && !(i % lull_mod))
309 +                       maybe_send_keepalive();
310 +
311                 if (verbose > 3) {
312                         rprintf(FINFO,
313                                 "chunk[%d] len=%d offset=%.0f sum1=%08x\n",