From: Timo Sirainen Date: Sun, 29 Oct 2017 22:59:01 +0000 (+0200) Subject: lib: Add o_stream_get_last_write_time() X-Git-Tag: 2.3.0.rc1~546 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8b6c3d6bc9d63665af5e0a3c8b604438e4c3a4e;p=thirdparty%2Fdovecot%2Fcore.git lib: Add o_stream_get_last_write_time() --- diff --git a/src/lib/ostream-private.h b/src/lib/ostream-private.h index d694fca577..e0a7d81be7 100644 --- a/src/lib/ostream-private.h +++ b/src/lib/ostream-private.h @@ -34,6 +34,8 @@ struct ostream_private { struct ostream *parent; /* for filter streams */ int fd; + struct timeval last_write_timeval; + stream_flush_callback_t *callback; void *context; diff --git a/src/lib/ostream.c b/src/lib/ostream.c index 03d33df273..ca2c506e13 100644 --- a/src/lib/ostream.c +++ b/src/lib/ostream.c @@ -275,6 +275,8 @@ o_stream_sendv_int(struct ostream *stream, const struct const_iovec *iov, i_assert(!_stream->finished); ret = _stream->sendv(_stream, iov, iov_count); + if (ret > 0) + stream->real_stream->last_write_timeval = ioloop_timeval; if (unlikely(ret != (ssize_t)total_size)) { if (ret < 0) { i_assert(stream->stream_errno != 0); @@ -406,6 +408,9 @@ o_stream_send_istream(struct ostream *outstream, struct istream *instream) /* non-failure - make sure stream offsets match */ i_assert((outstream->offset - old_outstream_offset) == (instream->v_offset - old_instream_offset)); + + if (outstream->offset != old_outstream_offset) + outstream->real_stream->last_write_timeval = ioloop_timeval; return res; } @@ -447,13 +452,21 @@ int o_stream_pwrite(struct ostream *stream, const void *data, size_t size, i_assert(!stream->real_stream->finished); ret = stream->real_stream->write_at(stream->real_stream, data, size, offset); - if (unlikely(ret < 0)) { + if (ret > 0) + stream->real_stream->last_write_timeval = ioloop_timeval; + else if (unlikely(ret < 0)) { i_assert(stream->stream_errno != 0); errno = stream->stream_errno; } + return ret; } +void o_stream_get_last_write_time(struct ostream *stream, struct timeval *tv_r) +{ + *tv_r = stream->real_stream->last_write_timeval; +} + enum ostream_send_istream_result io_stream_copy(struct ostream *outstream, struct istream *instream) { diff --git a/src/lib/ostream.h b/src/lib/ostream.h index 7b149a64f9..4f7d550ca1 100644 --- a/src/lib/ostream.h +++ b/src/lib/ostream.h @@ -200,6 +200,11 @@ void o_stream_nsend_istream(struct ostream *outstream, struct istream *instream) int o_stream_pwrite(struct ostream *stream, const void *data, size_t size, uoff_t offset); +/* Return the last timestamp when something was successfully sent to the + ostream's internal buffers (no guarantees that anything was sent further). + The timestamp is 0 if nothing has ever been written. */ +void o_stream_get_last_write_time(struct ostream *stream, struct timeval *tv_r); + /* If there are any I/O loop items associated with the stream, move all of them to current_ioloop. */ void o_stream_switch_ioloop(struct ostream *stream);