0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-10-18 09:58:43 +00:00

fixup! fixup! Lib: CBOR message streams and channels

This commit is contained in:
Maria Matejka 2024-10-11 21:31:03 +02:00
parent 50557d2b26
commit 65079628cf
3 changed files with 31 additions and 1 deletions

View File

@ -325,3 +325,12 @@ cbor_stream_attach(struct cbor_stream *stream, sock *sk)
sk->data = stream; sk->data = stream;
sk->rx_hook = cbor_stream_rx; sk->rx_hook = cbor_stream_rx;
} }
void
cbor_channel_done(struct cbor_channel *channel)
{
struct cbor_stream *stream = stream;
HASH_REMOVE(stream->channels, CCH, channel);
rp_free(channel->p);
sl_free(channel);
}

View File

@ -194,6 +194,25 @@ bool cbor_put_close(struct cbor_writer *w, u64 actual_size, bool strict)
/* Tags: TODO! */ /* Tags: TODO! */
/* Writer contexts */
struct cbor_writer *
cbor_reply_init(struct cbor_channel *cch)
{
struct cbor_writer *cw = &cch->writer;
if (cch->stream->s->tbuf != cch->stream->s->tpos)
bug("Not implemented reply to not-fully-flushed buffer");
cbor_writer_init(cw, cch->stream->writer_depth, cch->stream->s->tbuf, cch->stream->s->tbsize);
return cw;
}
void
cbor_reply_send(struct cbor_channel *cch, struct cbor_writer *cw)
{
ASSERT_DIE(cw == &cch->writer);
sk_send(cch->stream->s, cw->data.pos - cw->data.start);
}
#if 0 #if 0
void cbor_epoch_time(struct cbor_writer *writer, int64_t time, int shift) void cbor_epoch_time(struct cbor_writer *writer, int64_t time, int shift)

View File

@ -212,6 +212,7 @@ struct cbor_stream {
CSTR_FINISH, CSTR_FINISH,
CSTR_CLEANUP, CSTR_CLEANUP,
} state; } state;
uint writer_depth;
struct cbor_parser_context parser; struct cbor_parser_context parser;
}; };
@ -228,6 +229,7 @@ struct cbor_channel {
pool *p; pool *p;
u64 id; u64 id;
u64 idhash; u64 idhash;
struct cbor_writer writer;
}; };
extern struct cbor_channel cbor_channel_parse_error; extern struct cbor_channel cbor_channel_parse_error;
@ -236,7 +238,7 @@ extern struct cbor_channel cbor_channel_parse_error;
struct cbor_channel *cbor_channel_new(struct cbor_stream *); struct cbor_channel *cbor_channel_new(struct cbor_stream *);
/* Drop the channel */ /* Drop the channel */
void cbor_done_channel(struct cbor_channel *); void cbor_channel_done(struct cbor_channel *);
struct cbor_writer *cbor_reply_init(struct cbor_channel *); struct cbor_writer *cbor_reply_init(struct cbor_channel *);
void cbor_reply_send(struct cbor_channel *, struct cbor_writer *); void cbor_reply_send(struct cbor_channel *, struct cbor_writer *);