Mercurial > dovecot > core-2.2
annotate src/lib/istream-rawlog.c @ 22664:fea53c2725c0
director: Fix director_max_parallel_moves/kicks type
Should be uint, not time.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 09 Nov 2017 12:24:16 +0200 |
parents | 2e2563132d5f |
children | cb108f786fb4 |
rev | line source |
---|---|
21390
2e2563132d5f
Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
19552
diff
changeset
|
1 /* Copyright (c) 2011-2017 Dovecot authors, see the included COPYING file */ |
13534 | 2 |
3 #include "lib.h" | |
18166
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
4 #include "ostream.h" |
13534 | 5 #include "iostream-rawlog-private.h" |
6 #include "istream-private.h" | |
7 #include "istream-rawlog.h" | |
8 | |
9 struct rawlog_istream { | |
10 struct istream_private istream; | |
11 struct rawlog_iostream riostream; | |
12 }; | |
13 | |
16020
6cabb95d32ec
iostreams: Added close_parent flag to close() handler and clarified close/destroy APIs.
Timo Sirainen <tss@iki.fi>
parents:
16006
diff
changeset
|
14 static void i_stream_rawlog_close(struct iostream_private *stream, |
6cabb95d32ec
iostreams: Added close_parent flag to close() handler and clarified close/destroy APIs.
Timo Sirainen <tss@iki.fi>
parents:
16006
diff
changeset
|
15 bool close_parent) |
13534 | 16 { |
17 struct rawlog_istream *rstream = (struct rawlog_istream *)stream; | |
18 | |
19 iostream_rawlog_close(&rstream->riostream); | |
16020
6cabb95d32ec
iostreams: Added close_parent flag to close() handler and clarified close/destroy APIs.
Timo Sirainen <tss@iki.fi>
parents:
16006
diff
changeset
|
20 if (close_parent) |
6cabb95d32ec
iostreams: Added close_parent flag to close() handler and clarified close/destroy APIs.
Timo Sirainen <tss@iki.fi>
parents:
16006
diff
changeset
|
21 i_stream_close(rstream->istream.parent); |
13534 | 22 } |
23 | |
24 static void i_stream_rawlog_destroy(struct iostream_private *stream) | |
25 { | |
26 struct rawlog_istream *rstream = (struct rawlog_istream *)stream; | |
27 uoff_t v_offset; | |
28 | |
29 v_offset = rstream->istream.parent_start_offset + | |
30 rstream->istream.istream.v_offset; | |
31 if (rstream->istream.parent->seekable || | |
32 v_offset > rstream->istream.parent->v_offset) { | |
33 /* get to same position in parent stream */ | |
34 i_stream_seek(rstream->istream.parent, v_offset); | |
35 } | |
36 i_stream_unref(&rstream->istream.parent); | |
37 } | |
38 | |
39 static ssize_t i_stream_rawlog_read(struct istream_private *stream) | |
40 { | |
41 struct rawlog_istream *rstream = (struct rawlog_istream *)stream; | |
42 ssize_t ret; | |
43 size_t pos; | |
44 | |
45 i_stream_seek(stream->parent, rstream->istream.parent_start_offset + | |
46 stream->istream.v_offset); | |
47 | |
48 stream->pos -= stream->skip; | |
49 stream->skip = 0; | |
50 | |
51 stream->buffer = i_stream_get_data(stream->parent, &pos); | |
52 if (pos > stream->pos) | |
53 ret = 0; | |
54 else do { | |
55 if ((ret = i_stream_read(stream->parent)) == -2) | |
56 return -2; | |
57 | |
58 stream->istream.stream_errno = stream->parent->stream_errno; | |
59 stream->istream.eof = stream->parent->eof; | |
60 stream->buffer = i_stream_get_data(stream->parent, &pos); | |
61 } while (pos <= stream->pos && ret > 0); | |
62 | |
63 if (pos <= stream->pos) | |
64 ret = ret == 0 ? 0 : -1; | |
65 else { | |
66 ret = (ssize_t)(pos - stream->pos); | |
67 iostream_rawlog_write(&rstream->riostream, | |
68 stream->buffer + stream->pos, ret); | |
69 } | |
70 stream->pos = pos; | |
71 i_assert(ret != -1 || stream->istream.eof || | |
72 stream->istream.stream_errno != 0); | |
73 return ret; | |
74 } | |
75 | |
76 struct istream * | |
77 i_stream_create_rawlog(struct istream *input, const char *rawlog_path, | |
14967
8ce6d41d2d41
iostream-rawlog: Added possibility to save input/output to the same file.
Timo Sirainen <tss@iki.fi>
parents:
14701
diff
changeset
|
78 int rawlog_fd, enum iostream_rawlog_flags flags) |
13534 | 79 { |
18166
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
80 struct ostream *rawlog_output; |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
81 bool autoclose_fd = (flags & IOSTREAM_RAWLOG_FLAG_AUTOCLOSE) != 0; |
13534 | 82 |
83 i_assert(rawlog_path != NULL); | |
84 i_assert(rawlog_fd != -1); | |
85 | |
18166
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
86 rawlog_output = o_stream_create_fd(rawlog_fd, 0, autoclose_fd); |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
87 o_stream_set_name(rawlog_output, |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
88 t_strdup_printf("rawlog(%s)", rawlog_path)); |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
89 return i_stream_create_rawlog_from_stream(input, rawlog_output, flags); |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
90 } |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
91 |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
92 struct istream * |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
93 i_stream_create_rawlog_from_stream(struct istream *input, |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
94 struct ostream *rawlog_output, |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
95 enum iostream_rawlog_flags flags) |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
96 { |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
97 struct rawlog_istream *rstream; |
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
98 |
13534 | 99 rstream = i_new(struct rawlog_istream, 1); |
100 rstream->istream.max_buffer_size = input->real_stream->max_buffer_size; | |
14701
89e0aad6ba88
istreams: Added default stat() implementation for filter streams.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
101 rstream->istream.stream_size_passthrough = TRUE; |
89e0aad6ba88
istreams: Added default stat() implementation for filter streams.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
102 |
18166
c02f29ca104d
lib: iostream-rawlog now writes to ostreams instead of directly to fds.
Timo Sirainen <tss@iki.fi>
parents:
18137
diff
changeset
|
103 rstream->riostream.rawlog_output = rawlog_output; |
14967
8ce6d41d2d41
iostream-rawlog: Added possibility to save input/output to the same file.
Timo Sirainen <tss@iki.fi>
parents:
14701
diff
changeset
|
104 iostream_rawlog_init(&rstream->riostream, flags, TRUE); |
13534 | 105 |
106 rstream->istream.read = i_stream_rawlog_read; | |
107 rstream->istream.iostream.close = i_stream_rawlog_close; | |
108 rstream->istream.iostream.destroy = i_stream_rawlog_destroy; | |
109 | |
110 rstream->istream.istream.readable_fd = input->readable_fd; | |
111 rstream->istream.istream.blocking = input->blocking; | |
112 rstream->istream.istream.seekable = input->seekable; | |
113 return i_stream_create(&rstream->istream, input, | |
114 i_stream_get_fd(input)); | |
115 } |