]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add i_stream_get_last_read_time()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 29 Oct 2017 22:49:15 +0000 (00:49 +0200)
committerTimo Sirainen <tss@dovecot.fi>
Mon, 6 Nov 2017 23:09:00 +0000 (01:09 +0200)
src/lib/istream-private.h
src/lib/istream.c
src/lib/istream.h

index 4f9a0d70344acec997219862fdd0c25e6e395fdc..fd53da974dd25a92f425cb7e186d275abb639dad 100644 (file)
@@ -52,6 +52,8 @@ struct istream_private {
           this way streams can check if their parent streams have been
           accessed behind them. */
        unsigned int access_counter;
+       /* Timestamp when read() last returned >0 */
+       struct timeval last_read_timeval;
 
        string_t *line_str; /* for i_stream_next_line() if w_buffer == NULL */
        bool line_crlf:1;
index 2073e249444274f2c406b49119d61d354d1fe401..1b08d57e1a967ef3aa66544600bea0eaf2b9ec3e 100644 (file)
@@ -328,6 +328,7 @@ ssize_t i_stream_read_memarea(struct istream *stream)
                i_assert(ret > 0);
                i_assert(_stream->skip < _stream->pos);
                i_assert((size_t)ret+old_size == _stream->pos - _stream->skip);
+               _stream->last_read_timeval = ioloop_timeval;
                break;
        }
 
@@ -358,6 +359,11 @@ int i_stream_read_more_memarea(struct istream *stream,
        return ret;
 }
 
+void i_stream_get_last_read_time(struct istream *stream, struct timeval *tv_r)
+{
+       *tv_r = stream->real_stream->last_read_timeval;
+}
+
 ssize_t i_stream_read_copy_from_parent(struct istream *istream)
 {
        struct istream_private *stream = istream->real_stream;
index 549708d81602bb584db280254d69647d32aa189e..3c99bff641b8c1261189e606bd3cdce1d32e46c9 100644 (file)
@@ -221,6 +221,9 @@ i_stream_read_more(struct istream *stream, const unsigned char **data_r,
 {
        return i_stream_read_bytes(stream, data_r, size_r, 1);
 }
+/* Return the timestamp when istream last successfully read something.
+   The timestamp is 0 if nothing has ever been read. */
+void i_stream_get_last_read_time(struct istream *stream, struct timeval *tv_r);
 
 /* Append external data to input stream. Returns TRUE if successful, FALSE if
    there is not enough space in the stream. */