/src/dovecot/src/lib-fs/istream-fs-stats.c
Line | Count | Source |
1 | | /* Copyright (c) Dovecot authors, see top-level COPYING file */ |
2 | | |
3 | | #include "lib.h" |
4 | | #include "fs-api-private.h" |
5 | | #include "istream-private.h" |
6 | | #include "istream-fs-stats.h" |
7 | | |
8 | | struct fs_stats_istream { |
9 | | struct istream_private istream; |
10 | | struct fs_file *file; |
11 | | }; |
12 | | |
13 | | static ssize_t |
14 | | i_stream_fs_stats_read(struct istream_private *stream) |
15 | 0 | { |
16 | 0 | struct fs_stats_istream *sstream = (struct fs_stats_istream *)stream; |
17 | 0 | ssize_t ret; |
18 | |
|
19 | 0 | i_stream_seek(stream->parent, stream->parent_start_offset + |
20 | 0 | stream->istream.v_offset); |
21 | |
|
22 | 0 | ret = i_stream_read_copy_from_parent(&stream->istream); |
23 | 0 | if (ret > 0) { |
24 | | /* count the first returned bytes as the finish time, since |
25 | | we don't want to count the time caller spends on processing |
26 | | this stream. (only the first fs_file_timing_end() call |
27 | | actually does anything - the others are ignored.) */ |
28 | 0 | fs_file_timing_end(sstream->file, FS_OP_READ); |
29 | 0 | } |
30 | 0 | return ret; |
31 | 0 | } |
32 | | |
33 | | struct istream * |
34 | | i_stream_create_fs_stats(struct istream *input, struct fs_file *file) |
35 | 0 | { |
36 | 0 | struct fs_stats_istream *sstream; |
37 | |
|
38 | 0 | sstream = i_new(struct fs_stats_istream, 1); |
39 | 0 | sstream->file = file; |
40 | 0 | sstream->istream.max_buffer_size = input->real_stream->max_buffer_size; |
41 | 0 | sstream->istream.stream_size_passthrough = TRUE; |
42 | 0 | sstream->istream.read = i_stream_fs_stats_read; |
43 | 0 | sstream->istream.istream.blocking = input->blocking; |
44 | 0 | sstream->istream.istream.seekable = input->seekable; |
45 | 0 | return i_stream_create(&sstream->istream, input, |
46 | 0 | i_stream_get_fd(input), |
47 | 0 | ISTREAM_HIDDEN_INPUTS_NONE, 0); |
48 | 0 | } |