@matheusbsbs / matheus-bagliano / commits / d47f3db75c
Fork 0

Prepare larger packet buffer for upload-pack protocol.

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>

Junio C Hamano committed Sep 10, 2006 at 16:27 UTC d47f3db75c58139cdcbca5cc63b17bf5db293b6a
4 files changed +20 -9
fetch-clone.c
+1 -1
@@ -115,7 +115,7 @@ static pid_t setup_sideband(int sideband, const char *me, int fd[2], int xd[2])
115 die("%s: unable to fork off sideband demultiplexer", me);
116 if (!side_pid) {
117 /* subprocess */
118 - char buf[DEFAULT_PACKET_MAX];
118 + char buf[LARGE_PACKET_MAX];
119
120 close(fd[0]);
121 if (xd[0] != xd[1])
fetch-pack.c
+9 -3
@@ -166,10 +166,11 @@ static int find_common(int fd[2], unsigned char *result_sha1,
166 }
167
168 if (!fetching)
169 - packet_write(fd[1], "want %s%s%s%s\n",
169 + packet_write(fd[1], "want %s%s%s%s%s\n",
170 sha1_to_hex(remote),
171 (multi_ack ? " multi_ack" : ""),
172 - (use_sideband ? " side-band" : ""),
172 + (use_sideband == 2 ? " side-band-64k" : ""),
173 + (use_sideband == 1 ? " side-band" : ""),
174 (use_thin_pack ? " thin-pack" : ""));
175 else
176 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)
427 fprintf(stderr, "Server supports multi_ack\n");
428 multi_ack = 1;
429 }
429 - if (server_supports("side-band")) {
430 + if (server_supports("side-band-64k")) {
431 + if (verbose)
432 + fprintf(stderr, "Server supports side-band-64k\n");
433 + use_sideband = 2;
434 + }
435 + else if (server_supports("side-band")) {
436 if (verbose)
437 fprintf(stderr, "Server supports side-band\n");
438 use_sideband = 1;
sideband.h
+1
@@ -5,6 +5,7 @@
5 #define SIDEBAND_REMOTE_ERROR -1
6
7 #define DEFAULT_PACKET_MAX 1000
8 +#define LARGE_PACKET_MAX 65520
9
10 int recv_sideband(const char *me, int in_stream, int out, int err, char *, int);
11 ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max);
upload-pack.c
+9 -5
@@ -20,6 +20,9 @@ static int use_thin_pack;
20 static struct object_array have_obj;
21 static struct object_array want_obj;
22 static unsigned int timeout;
23 +/* 0 for no sideband,
24 + * otherwise maximum packet size (up to 65520 bytes).
25 + */
26 static int use_sideband;
27
28 static void reset_timeout(void)
@@ -37,8 +40,7 @@ static int strip(char *line, int len)
40 static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
41 {
42 if (use_sideband)
40 - return send_sideband(1, fd, data, sz, DEFAULT_PACKET_MAX);
41 -
43 + return send_sideband(1, fd, data, sz, use_sideband);
44 if (fd == 3)
45 /* emergency quit */
46 fd = 2;
@@ -389,8 +391,10 @@ static void receive_needs(void)
391 multi_ack = 1;
392 if (strstr(line+45, "thin-pack"))
393 use_thin_pack = 1;
392 - if (strstr(line+45, "side-band"))
393 - use_sideband = 1;
394 + if (strstr(line+45, "side-band-64k"))
395 + use_sideband = LARGE_PACKET_MAX;
396 + else if (strstr(line+45, "side-band"))
397 + use_sideband = DEFAULT_PACKET_MAX;
398
399 /* We have sent all our refs already, and the other end
400 * should have chosen out of them; otherwise they are
@@ -412,7 +416,7 @@ static void receive_needs(void)
416
417 static int send_ref(const char *refname, const unsigned char *sha1)
418 {
415 - static const char *capabilities = "multi_ack thin-pack side-band";
419 + static const char *capabilities = "multi_ack thin-pack side-band side-band-64k";
420 struct object *o = parse_object(sha1);
421
422 if (!o)