Change the daemon-timeout conveyance into a protocol-31 message.
authorWayne Davison <wayned@samba.org>
Tue, 27 Oct 2009 19:34:39 +0000 (12:34 -0700)
committerWayne Davison <wayned@samba.org>
Tue, 27 Oct 2009 19:38:04 +0000 (12:38 -0700)
compat.c
io.c
main.c
rsync.h

index d7e90be..f5cfbd4 100644 (file)
--- a/compat.c
+++ b/compat.c
@@ -27,8 +27,6 @@ int inc_recurse = 0;
 
 extern int am_server;
 extern int am_sender;
-extern int am_daemon;
-extern int io_timeout;
 extern int local_server;
 extern int inplace;
 extern int recurse;
@@ -74,7 +72,6 @@ int filesfrom_convert = 0;
 #define CF_INC_RECURSE  (1<<0)
 #define CF_SYMLINK_TIMES (1<<1)
 #define CF_SYMLINK_ICONV (1<<2)
-#define CF_TIMEOUT_ACTIVE (1<<3)
 
 static const char *client_info;
 
@@ -257,21 +254,9 @@ void setup_protocol(int f_out,int f_in)
 #ifdef ICONV_OPTION
                        compat_flags |= CF_SYMLINK_ICONV;
 #endif
-                       if (am_daemon && io_timeout && protocol_version >= 31)
-                               compat_flags |= CF_TIMEOUT_ACTIVE;
                        write_byte(f_out, compat_flags);
-                       if (compat_flags & CF_TIMEOUT_ACTIVE)
-                               write_varint(f_out, io_timeout);
                } else {
                        compat_flags = read_byte(f_in);
-                       if (compat_flags & CF_TIMEOUT_ACTIVE) {
-                               int timeout = read_varint(f_in);
-                               if (!io_timeout || io_timeout > timeout) {
-                                       if (INFO_GTE(MISC, 2))
-                                               rprintf(FINFO, "Setting --timeout=%d to match server\n", timeout);
-                                       io_timeout = timeout;
-                               }
-                       }
                }
                /* The inc_recurse var MUST be set to 0 or 1. */
                inc_recurse = compat_flags & CF_INC_RECURSE ? 1 : 0;
diff --git a/io.c b/io.c
index b400ba2..a85bcfa 100644 (file)
--- a/io.c
+++ b/io.c
@@ -1264,7 +1264,7 @@ void stop_flist_forward(void)
 static void read_a_msg(void)
 {
        char *data, line[BIGPATHBUFLEN];
-       int tag;
+       int tag, val;
        size_t msg_bytes;
 
        data = perform_io(4, PIO_INPUT_AND_CONSUME);
@@ -1306,6 +1306,17 @@ static void read_a_msg(void)
                if (!am_generator)
                        send_msg(MSG_IO_ERROR, data, 4, 0);
                break;
+       case MSG_IO_TIMEOUT:
+               if (msg_bytes != 4 || am_sender || am_generator)
+                       goto invalid_msg;
+               data = perform_io(4, PIO_INPUT_AND_CONSUME);
+               val = IVAL(data, 0);
+               if (!io_timeout || io_timeout > val) {
+                       if (INFO_GTE(MISC, 2))
+                               rprintf(FINFO, "Setting --timeout=%d to match server\n", val);
+                       io_timeout = val;
+               }
+               break;
        case MSG_NOOP:
                if (am_sender)
                        maybe_send_keepalive();
diff --git a/main.c b/main.c
index a8f285a..00da2db 100644 (file)
--- a/main.c
+++ b/main.c
@@ -29,6 +29,7 @@
 
 extern int dry_run;
 extern int list_only;
+extern int io_timeout;
 extern int am_root;
 extern int am_server;
 extern int am_sender;
@@ -1051,6 +1052,8 @@ void start_server(int f_in, int f_out, int argc, char *argv[])
 
        if (protocol_version >= 23)
                io_start_multiplex_out(f_out);
+       if (am_daemon && io_timeout && protocol_version >= 31)
+               send_msg_int(MSG_IO_TIMEOUT, io_timeout);
 
        if (am_sender) {
                keep_dirlinks = 0; /* Must be disabled on the sender. */
diff --git a/rsync.h b/rsync.h
index 48ebe67..522ffc5 100644 (file)
--- a/rsync.h
+++ b/rsync.h
@@ -98,7 +98,7 @@
 /* This is used when working on a new protocol version in CVS, and should
  * be a new non-zero value for each CVS change that affects the protocol.
  * It must ALWAYS be 0 when the protocol goes final (and NEVER before)! */
-#define SUBPROTOCOL_VERSION 9
+#define SUBPROTOCOL_VERSION 10
 
 /* We refuse to interoperate with versions that are not in this range.
  * Note that we assume we'll work with later versions: the onus is on
@@ -231,6 +231,7 @@ enum msgcode {
        MSG_REDO=9,     /* reprocess indicated flist index */
        MSG_STATS=10,   /* message has stats data for generator */
        MSG_IO_ERROR=22,/* the sending side had an I/O error */
+       MSG_IO_TIMEOUT=33,/* tell client about a daemon's timeout value */
        MSG_NOOP=42,    /* a do-nothing message */
        MSG_SUCCESS=100,/* successfully updated indicated flist index */
        MSG_DELETED=101,/* successfully deleted a file on receiving side */