]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: ostream-multiplex - Implement the new get_buffer_used/avail_size() APIs
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 24 Feb 2018 20:04:11 +0000 (22:04 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 13 Mar 2018 07:17:04 +0000 (09:17 +0200)
src/lib/ostream-multiplex.c

index fdf4702350407c60da07af508ae38417b301fdff..17e3f86cfa58ea1eefdbec4c9f65216aa1996842 100644 (file)
@@ -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);