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 <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
74b082ad34
commit
0181b600a6
@ -127,6 +127,7 @@ enum protocol_version discover_version(struct packet_reader *reader)
|
||||
die_initial_contact(0);
|
||||
case PACKET_READ_FLUSH:
|
||||
case PACKET_READ_DELIM:
|
||||
case PACKET_READ_RESPONSE_END:
|
||||
version = protocol_v0;
|
||||
break;
|
||||
case PACKET_READ_NORMAL:
|
||||
@ -310,6 +311,7 @@ struct ref **get_remote_heads(struct packet_reader *reader,
|
||||
state = EXPECTING_DONE;
|
||||
break;
|
||||
case PACKET_READ_DELIM:
|
||||
case PACKET_READ_RESPONSE_END:
|
||||
die(_("invalid packet"));
|
||||
}
|
||||
|
||||
|
11
pkt-line.c
11
pkt-line.c
@ -99,6 +99,13 @@ void packet_delim(int fd)
|
||||
die_errno(_("unable to write delim packet"));
|
||||
}
|
||||
|
||||
void packet_response_end(int fd)
|
||||
{
|
||||
packet_trace("0002", 4, 1);
|
||||
if (write_in_full(fd, "0002", 4) < 0)
|
||||
die_errno(_("unable to write stateless separator packet"));
|
||||
}
|
||||
|
||||
int packet_flush_gently(int fd)
|
||||
{
|
||||
packet_trace("0000", 4, 1);
|
||||
@ -337,6 +344,10 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
|
||||
packet_trace("0001", 4, 0);
|
||||
*pktlen = 0;
|
||||
return PACKET_READ_DELIM;
|
||||
} else if (len == 2) {
|
||||
packet_trace("0002", 4, 0);
|
||||
*pktlen = 0;
|
||||
return PACKET_READ_RESPONSE_END;
|
||||
} else if (len < 4) {
|
||||
die(_("protocol error: bad line length %d"), len);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
*/
|
||||
void packet_flush(int fd);
|
||||
void packet_delim(int fd);
|
||||
void packet_response_end(int fd);
|
||||
void packet_write_fmt(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
|
||||
void packet_buf_flush(struct strbuf *buf);
|
||||
void packet_buf_delim(struct strbuf *buf);
|
||||
@ -94,6 +95,7 @@ enum packet_read_status {
|
||||
PACKET_READ_NORMAL,
|
||||
PACKET_READ_FLUSH,
|
||||
PACKET_READ_DELIM,
|
||||
PACKET_READ_RESPONSE_END,
|
||||
};
|
||||
enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
|
||||
size_t *src_len, char *buffer,
|
||||
|
@ -601,6 +601,8 @@ static int rpc_read_from_out(struct rpc_state *rpc, int options,
|
||||
case PACKET_READ_FLUSH:
|
||||
memcpy(buf - 4, "0000", 4);
|
||||
break;
|
||||
case PACKET_READ_RESPONSE_END:
|
||||
die(_("remote server sent stateless separator"));
|
||||
}
|
||||
}
|
||||
|
||||
|
2
serve.c
2
serve.c
@ -217,6 +217,8 @@ static int process_request(void)
|
||||
|
||||
state = PROCESS_REQUEST_DONE;
|
||||
break;
|
||||
case PACKET_READ_RESPONSE_END:
|
||||
BUG("unexpected stateless separator packet");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,9 @@ static void unpack(void)
|
||||
case PACKET_READ_DELIM:
|
||||
printf("0001\n");
|
||||
break;
|
||||
case PACKET_READ_RESPONSE_END:
|
||||
printf("0002\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -75,6 +78,7 @@ static void unpack_sideband(void)
|
||||
case PACKET_READ_FLUSH:
|
||||
return;
|
||||
case PACKET_READ_DELIM:
|
||||
case PACKET_READ_RESPONSE_END:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user