summaryrefslogtreecommitdiff
path: root/pkt-line.c
diff options
context:
space:
mode:
authorBrandon Williams <bmwill@google.com>2018-03-14 18:31:40 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-03-14 21:15:06 (GMT)
commita4cfd41c7be81c10b925532979e81e4d07f6b376 (patch)
treecda6b41e43b63dd5956caab45063dba6dd642826 /pkt-line.c
parent77dabc14c497d2498b814967bf21a3ed1618207f (diff)
downloadgit-a4cfd41c7be81c10b925532979e81e4d07f6b376.zip
git-a4cfd41c7be81c10b925532979e81e4d07f6b376.tar.gz
git-a4cfd41c7be81c10b925532979e81e4d07f6b376.tar.bz2
pkt-line: add delim packet support
One of the design goals of protocol-v2 is to improve the semantics of flush packets. Currently in protocol-v1, flush packets are used both to indicate a break in a list of packet lines as well as an indication that one side has finished speaking. This makes it particularly difficult to implement proxies as a proxy would need to completely understand git protocol instead of simply looking for a flush packet. To do this, introduce the special deliminator packet '0001'. A delim packet can then be used as a deliminator between lists of packet lines while flush packets can be reserved to indicate the end of a response. Documentation for how this packet will be used in protocol v2 will included in a future patch. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pkt-line.c')
-rw-r--r--pkt-line.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/pkt-line.c b/pkt-line.c
index 1881dc8..7296731 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -91,6 +91,12 @@ void packet_flush(int fd)
write_or_die(fd, "0000", 4);
}
+void packet_delim(int fd)
+{
+ packet_trace("0001", 4, 1);
+ write_or_die(fd, "0001", 4);
+}
+
int packet_flush_gently(int fd)
{
packet_trace("0000", 4, 1);
@@ -105,6 +111,12 @@ void packet_buf_flush(struct strbuf *buf)
strbuf_add(buf, "0000", 4);
}
+void packet_buf_delim(struct strbuf *buf)
+{
+ packet_trace("0001", 4, 1);
+ strbuf_add(buf, "0001", 4);
+}
+
static void set_packet_header(char *buf, const int size)
{
static char hexchar[] = "0123456789abcdef";
@@ -301,6 +313,10 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
packet_trace("0000", 4, 0);
*pktlen = 0;
return PACKET_READ_FLUSH;
+ } else if (len == 1) {
+ packet_trace("0001", 4, 0);
+ *pktlen = 0;
+ return PACKET_READ_DELIM;
} else if (len < 4) {
die("protocol error: bad line length %d", len);
}