git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Franck Bui-Huu <vagabon.xyz@gmail.com>
Cc: git@vger.kernel.org, Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Subject: [PATCH] Move sideband server side support into reusable form.
Date: Sun, 10 Sep 2006 03:37:44 -0700	[thread overview]
Message-ID: <7v8xkst3bb.fsf_-_@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <7vk64ctctv.fsf@assigned-by-dhcp.cox.net> (Junio C. Hamano's message of "Sun, 10 Sep 2006 00:12:12 -0700")

The server side support; this is just the very low level, and the
caller needs to know which band it wants to send things out.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * With the previous downloader-side support, this should make
   it easier to add the status notification from git-archive
   --remote over git native transport (aka git-daemon).

 sideband.c    |   26 ++++++++++++++++++++++++++
 sideband.h    |    1 +
 upload-pack.c |   50 +++++++++++++-------------------------------------
 3 files changed, 40 insertions(+), 37 deletions(-)

diff --git a/sideband.c b/sideband.c
index 861f621..1b14ff8 100644
--- a/sideband.c
+++ b/sideband.c
@@ -46,3 +46,29 @@ int recv_sideband(const char *me, int in
 	}
 	return 0;
 }
+
+/*
+ * fd is connected to the remote side; send the sideband data
+ * over multiplexed packet stream.
+ */
+ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max)
+{
+	ssize_t ssz = sz;
+	const char *p = data;
+
+	while (sz) {
+		unsigned n;
+		char hdr[5];
+
+		n = sz;
+		if (packet_max - 5 < n)
+			n = packet_max - 5;
+		sprintf(hdr, "%04x", n + 5);
+		hdr[4] = band;
+		safe_write(fd, hdr, 5);
+		safe_write(fd, p, n);
+		p += n;
+		sz -= n;
+	}
+	return ssz;
+}
diff --git a/sideband.h b/sideband.h
index 90b3855..c645cf2 100644
--- a/sideband.h
+++ b/sideband.h
@@ -7,5 +7,6 @@ #define SIDEBAND_REMOTE_ERROR -1
 #define DEFAULT_PACKET_MAX 1000
 
 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);
 
 #endif
diff --git a/upload-pack.c b/upload-pack.c
index 51ce936..1f2f7f7 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -4,6 +4,7 @@ #include <sys/poll.h>
 #include "cache.h"
 #include "refs.h"
 #include "pkt-line.h"
+#include "sideband.h"
 #include "tag.h"
 #include "object.h"
 #include "commit.h"
@@ -33,45 +34,19 @@ static int strip(char *line, int len)
 	return len;
 }
 
-#define PACKET_MAX 1000
 static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
 {
-	ssize_t ssz;
-	const char *p;
-
-	if (!data) {
-		if (!use_sideband)
-			return 0;
-		packet_flush(1);
-	}
-
-	if (!use_sideband) {
-		if (fd == 3)
-			/* emergency quit */
-			fd = 2;
-		if (fd == 2) {
-			xwrite(fd, data, sz);
-			return sz;
-		}
-		return safe_write(fd, data, sz);
-	}
-	p = data;
-	ssz = sz;
-	while (sz) {
-		unsigned n;
-		char hdr[5];
-
-		n = sz;
-		if (PACKET_MAX - 5 < n)
-			n = PACKET_MAX - 5;
-		sprintf(hdr, "%04x", n + 5);
-		hdr[4] = fd;
-		safe_write(1, hdr, 5);
-		safe_write(1, p, n);
-		p += n;
-		sz -= n;
+	if (use_sideband)
+		return send_sideband(1, fd, data, sz, DEFAULT_PACKET_MAX);
+
+	if (fd == 3)
+		/* emergency quit */
+		fd = 2;
+	if (fd == 2) {
+		xwrite(fd, data, sz);
+		return sz;
 	}
-	return ssz;
+	return safe_write(fd, data, sz);
 }
 
 static void create_pack_file(void)
@@ -308,7 +283,8 @@ static void create_pack_file(void)
 				goto fail;
 			fprintf(stderr, "flushed.\n");
 		}
-		send_client_data(1, NULL, 0);
+		if (use_sideband)
+			packet_flush(1);
 		return;
 	}
  fail:
-- 
1.4.2.gc52f

  parent reply	other threads:[~2006-09-10 10:37 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-10  7:09 [PATCH 1/2] archive: allow remote to have more formats than we understand Junio C Hamano
2006-09-10  7:12 ` [PATCH 2/2] Add --verbose to git-archive Junio C Hamano
2006-09-10 10:36   ` [PATCH 1/3] Move sideband client side support into reusable form Junio C Hamano
2006-09-10 19:15     ` Franck Bui-Huu
2006-09-10 10:37   ` Junio C Hamano [this message]
2006-09-10 10:47   ` [PATCH 3/3] Add sideband status report to git-archive protocol Junio C Hamano
2006-09-10 15:58     ` [PATCH] git-upload-archive: add config option to allow only specified formats Rene Scharfe
2006-09-10 16:12       ` Rene Scharfe
2006-09-10 18:00       ` Junio C Hamano
2006-09-11 21:41         ` Rene Scharfe
2006-09-11 21:50           ` Jakub Narebski
2006-09-10 19:07       ` Franck Bui-Huu
2006-09-11 21:55         ` Rene Scharfe
2006-09-10 19:15     ` [PATCH 3/3] Add sideband status report to git-archive protocol Franck Bui-Huu
2006-09-10 20:31       ` Junio C Hamano
2006-09-11 10:34     ` Franck Bui-Huu
2006-09-12  7:24       ` Junio C Hamano
2006-09-12  8:17         ` Franck Bui-Huu
2006-09-12  8:45           ` Franck Bui-Huu
2006-09-12  9:00             ` [PATCH] connect.c: finish_connect(): allow null pid parameter Franck Bui-Huu
2006-09-13  4:48               ` Junio C Hamano
2006-09-13  8:26                 ` [PATCH] Test return value of finish_connect() Franck Bui-Huu
2006-09-13  8:32                 ` [PATCH] git_connect: change return type to pid_t Franck Bui-Huu
2006-09-12 23:44           ` [PATCH 3/3] Add sideband status report to git-archive protocol Junio C Hamano
2006-09-10 12:05 ` [PATCH 1/2] archive: allow remote to have more formats than we understand Rene Scharfe
2006-09-10 19:02 ` Franck Bui-Huu
2006-09-10 19:07   ` Junio C Hamano
2006-09-10 19:18     ` Franck Bui-Huu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v8xkst3bb.fsf_-_@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    --cc=rene.scharfe@lsrfire.ath.cx \
    --cc=vagabon.xyz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).