From: Timo Sirainen Date: Sat, 24 Feb 2018 20:04:11 +0000 (+0200) Subject: lib: ostream-multiplex - Implement the new get_buffer_used/avail_size() APIs X-Git-Tag: 2.3.1~46 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7b4f32ab7e5fd270dd87ac26e3ad1c7a08c584eb;p=thirdparty%2Fdovecot%2Fcore.git lib: ostream-multiplex - Implement the new get_buffer_used/avail_size() APIs --- diff --git a/src/lib/ostream-multiplex.c b/src/lib/ostream-multiplex.c index fdf4702350..17e3f86cfa 100644 --- a/src/lib/ostream-multiplex.c +++ b/src/lib/ostream-multiplex.c @@ -126,6 +126,26 @@ o_stream_multiplex_ochannel_sendv(struct ostream_private *stream, return total; } +static size_t +o_stream_multiplex_ochannel_get_buffer_used_size(const struct ostream_private *stream) +{ + const struct multiplex_ochannel *channel = + (const struct multiplex_ochannel*)stream; + + return channel->buf->used + channel->mstream->wbuf->used + + o_stream_get_buffer_used_size(channel->mstream->parent); +} + +static size_t +o_stream_multiplex_ochannel_get_buffer_avail_size(const struct ostream_private *stream) +{ + const struct multiplex_ochannel *channel = + (const struct multiplex_ochannel*)stream; + + return channel->mstream->bufsize <= channel->buf->used ? 0 : + channel->mstream->bufsize - channel->buf->used; +} + static void o_stream_multiplex_ochannel_close(struct iostream_private *stream, bool close_parent) { @@ -179,6 +199,10 @@ o_stream_add_channel_real(struct multiplex_ostream *mstream, uint8_t cid) channel->buf = buffer_create_dynamic(default_pool, 256); channel->mstream = mstream; channel->ostream.sendv = o_stream_multiplex_ochannel_sendv; + channel->ostream.get_buffer_used_size = + o_stream_multiplex_ochannel_get_buffer_used_size; + channel->ostream.get_buffer_avail_size = + o_stream_multiplex_ochannel_get_buffer_avail_size; channel->ostream.iostream.close = o_stream_multiplex_ochannel_close; channel->ostream.iostream.destroy = o_stream_multiplex_ochannel_destroy; channel->ostream.fd = o_stream_get_fd(mstream->parent);