Skip to content

Commit 0181b60

Browse files
Denton-Lgitster
authored andcommitted
pkt-line: define PACKET_READ_RESPONSE_END
In a future commit, we will use PACKET_READ_RESPONSE_END to separate messages proxied by remote-curl. To prepare for this, add the PACKET_READ_RESPONSE_END enum value. In switch statements that need a case added, die() or BUG() when a PACKET_READ_RESPONSE_END is unexpected. Otherwise, mirror how PACKET_READ_DELIM is implemented (especially in cases where packets are being forwarded). Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 74b082a commit 0181b60

File tree

6 files changed

+23
-0
lines changed

6 files changed

+23
-0
lines changed

connect.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ enum protocol_version discover_version(struct packet_reader *reader)
127127
die_initial_contact(0);
128128
case PACKET_READ_FLUSH:
129129
case PACKET_READ_DELIM:
130+
case PACKET_READ_RESPONSE_END:
130131
version = protocol_v0;
131132
break;
132133
case PACKET_READ_NORMAL:
@@ -310,6 +311,7 @@ struct ref **get_remote_heads(struct packet_reader *reader,
310311
state = EXPECTING_DONE;
311312
break;
312313
case PACKET_READ_DELIM:
314+
case PACKET_READ_RESPONSE_END:
313315
die(_("invalid packet"));
314316
}
315317

pkt-line.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ void packet_delim(int fd)
9999
die_errno(_("unable to write delim packet"));
100100
}
101101

102+
void packet_response_end(int fd)
103+
{
104+
packet_trace("0002", 4, 1);
105+
if (write_in_full(fd, "0002", 4) < 0)
106+
die_errno(_("unable to write stateless separator packet"));
107+
}
108+
102109
int packet_flush_gently(int fd)
103110
{
104111
packet_trace("0000", 4, 1);
@@ -337,6 +344,10 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
337344
packet_trace("0001", 4, 0);
338345
*pktlen = 0;
339346
return PACKET_READ_DELIM;
347+
} else if (len == 2) {
348+
packet_trace("0002", 4, 0);
349+
*pktlen = 0;
350+
return PACKET_READ_RESPONSE_END;
340351
} else if (len < 4) {
341352
die(_("protocol error: bad line length %d"), len);
342353
}

pkt-line.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
void packet_flush(int fd);
2424
void packet_delim(int fd);
25+
void packet_response_end(int fd);
2526
void packet_write_fmt(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
2627
void packet_buf_flush(struct strbuf *buf);
2728
void packet_buf_delim(struct strbuf *buf);
@@ -94,6 +95,7 @@ enum packet_read_status {
9495
PACKET_READ_NORMAL,
9596
PACKET_READ_FLUSH,
9697
PACKET_READ_DELIM,
98+
PACKET_READ_RESPONSE_END,
9799
};
98100
enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
99101
size_t *src_len, char *buffer,

remote-curl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,8 @@ static int rpc_read_from_out(struct rpc_state *rpc, int options,
601601
case PACKET_READ_FLUSH:
602602
memcpy(buf - 4, "0000", 4);
603603
break;
604+
case PACKET_READ_RESPONSE_END:
605+
die(_("remote server sent stateless separator"));
604606
}
605607
}
606608

serve.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ static int process_request(void)
217217

218218
state = PROCESS_REQUEST_DONE;
219219
break;
220+
case PACKET_READ_RESPONSE_END:
221+
BUG("unexpected stateless separator packet");
220222
}
221223
}
222224

t/helper/test-pkt-line.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ static void unpack(void)
4646
case PACKET_READ_DELIM:
4747
printf("0001\n");
4848
break;
49+
case PACKET_READ_RESPONSE_END:
50+
printf("0002\n");
51+
break;
4952
}
5053
}
5154
}
@@ -75,6 +78,7 @@ static void unpack_sideband(void)
7578
case PACKET_READ_FLUSH:
7679
return;
7780
case PACKET_READ_DELIM:
81+
case PACKET_READ_RESPONSE_END:
7882
break;
7983
}
8084
}

0 commit comments

Comments
 (0)