Prepare larger packet buffer for upload-pack protocol.
authorJunio C Hamano <junkio@cox.net>
Sun, 10 Sep 2006 23:27:08 +0000 (16:27 -0700)
committerJunio C Hamano <junkio@cox.net>
Sun, 10 Sep 2006 23:27:08 +0000 (16:27 -0700)
The original side-band support added to the upload-pack protocol used the
default 1000-byte packet length.  The pkt-line format allows up to 64k, so
prepare the receiver for the maximum size, and have the uploader and
downloader negotiate if larger packet length is allowed.

Signed-off-by: Junio C Hamano <junkio@cox.net>
fetch-clone.c
fetch-pack.c
sideband.h
upload-pack.c

index b62feac..b632ca0 100644 (file)
@@ -115,7 +115,7 @@ static pid_t setup_sideband(int sideband, const char *me, int fd[2], int xd[2])
                die("%s: unable to fork off sideband demultiplexer", me);
        if (!side_pid) {
                /* subprocess */
-               char buf[DEFAULT_PACKET_MAX];
+               char buf[LARGE_PACKET_MAX];
 
                close(fd[0]);
                if (xd[0] != xd[1])
index 377fede..1b2d6ee 100644 (file)
@@ -166,10 +166,11 @@ static int find_common(int fd[2], unsigned char *result_sha1,
                }
 
                if (!fetching)
-                       packet_write(fd[1], "want %s%s%s%s\n",
+                       packet_write(fd[1], "want %s%s%s%s%s\n",
                                     sha1_to_hex(remote),
                                     (multi_ack ? " multi_ack" : ""),
-                                    (use_sideband ? " side-band" : ""),
+                                    (use_sideband == 2 ? " side-band-64k" : ""),
+                                    (use_sideband == 1 ? " side-band" : ""),
                                     (use_thin_pack ? " thin-pack" : ""));
                else
                        packet_write(fd[1], "want %s\n", sha1_to_hex(remote));
@@ -426,7 +427,12 @@ static int fetch_pack(int fd[2], int nr_match, char **match)
                        fprintf(stderr, "Server supports multi_ack\n");
                multi_ack = 1;
        }
-       if (server_supports("side-band")) {
+       if (server_supports("side-band-64k")) {
+               if (verbose)
+                       fprintf(stderr, "Server supports side-band-64k\n");
+               use_sideband = 2;
+       }
+       else if (server_supports("side-band")) {
                if (verbose)
                        fprintf(stderr, "Server supports side-band\n");
                use_sideband = 1;
index c645cf2..4872106 100644 (file)
@@ -5,6 +5,7 @@
 #define SIDEBAND_REMOTE_ERROR -1
 
 #define DEFAULT_PACKET_MAX 1000
+#define LARGE_PACKET_MAX 65520
 
 int recv_sideband(const char *me, int in_stream, int out, int err, char *, int);
 ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max);
index 1f2f7f7..b673d8c 100644 (file)
@@ -20,6 +20,9 @@ static int use_thin_pack;
 static struct object_array have_obj;
 static struct object_array want_obj;
 static unsigned int timeout;
+/* 0 for no sideband,
+ * otherwise maximum packet size (up to 65520 bytes).
+ */
 static int use_sideband;
 
 static void reset_timeout(void)
@@ -37,8 +40,7 @@ static int strip(char *line, int len)
 static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
 {
        if (use_sideband)
-               return send_sideband(1, fd, data, sz, DEFAULT_PACKET_MAX);
-
+               return send_sideband(1, fd, data, sz, use_sideband);
        if (fd == 3)
                /* emergency quit */
                fd = 2;
@@ -389,8 +391,10 @@ static void receive_needs(void)
                        multi_ack = 1;
                if (strstr(line+45, "thin-pack"))
                        use_thin_pack = 1;
-               if (strstr(line+45, "side-band"))
-                       use_sideband = 1;
+               if (strstr(line+45, "side-band-64k"))
+                       use_sideband = LARGE_PACKET_MAX;
+               else if (strstr(line+45, "side-band"))
+                       use_sideband = DEFAULT_PACKET_MAX;
 
                /* We have sent all our refs already, and the other end
                 * should have chosen out of them; otherwise they are
@@ -412,7 +416,7 @@ static void receive_needs(void)
 
 static int send_ref(const char *refname, const unsigned char *sha1)
 {
-       static const char *capabilities = "multi_ack thin-pack side-band";
+       static const char *capabilities = "multi_ack thin-pack side-band side-band-64k";
        struct object *o = parse_object(sha1);
 
        if (!o)