Send packet-stream goodbye

This helps some streams to close.
main
cel 6 years ago
parent 25b777fa9d
commit ebc79b13c5

@ -53,6 +53,7 @@ struct boxs {
size_t rx_buf_pos;
size_t rx_buf_len;
bool noauth;
bool wrote_goodbye;
};
enum pkt_type {
@ -330,6 +331,7 @@ static void shs_connect(int sfd, int infd, int outfd, const unsigned char pubkey
bs->rx_buf_len = 0;
bs->s = sfd;
bs->noauth = false;
bs->wrote_goodbye = false;
}
static int pubkey_decode(const char *key_str, unsigned char key[32]) {
@ -630,6 +632,12 @@ static void ps_write(struct boxs *bs, const char *data, size_t len, enum pkt_typ
bs_write(bs, out_buf, out_len);
}
static void ps_goodbye(struct boxs *bs) {
if (bs->wrote_goodbye) return;
bs->wrote_goodbye = true;
bs_write(bs, zeros, 9);
}
static int ps_read_header(struct boxs *bs, size_t *len, int *req_id, enum pkt_flags *flags) {
char buf[9];
struct pkt_header header;
@ -702,6 +710,7 @@ static enum stream_state muxrpc_read_source_1(struct boxs *bs, int outfd, int re
int rc = ps_read_header(bs, &len, &req, &flags);
if (rc < 0) err(1, "ps_read_header");
if (req == 0 && len == 0) {
if (bs->wrote_goodbye) return stream_state_ended_ok;
warnx("unexpected end of parent stream");
return stream_state_ended_error;
}
@ -766,6 +775,7 @@ static enum stream_state muxrpc_write_sink_1(struct boxs *bs, int infd,
if (sz < 0) err(1, "read");
if (sz == 0) {
ps_write(bs, "true", 4, pkt_type_json, req_id, true, true);
ps_goodbye(bs);
return stream_state_ended_ok;
}
ps_write(bs, buf, sz, ptype, req_id, true, false);

Loading…
Cancel
Save