dovecot-2.0-sslstream: Added tee_i_stream_child_is_waiting().
dovecot at dovecot.org
dovecot at dovecot.org
Sat Feb 13 02:56:40 EET 2010
details: http://hg.dovecot.org/dovecot-2.0-sslstream/rev/9d878b1dc028
changeset: 10393:9d878b1dc028
user: Timo Sirainen <tss at iki.fi>
date: Mon Nov 23 15:42:55 2009 -0500
description:
Added tee_i_stream_child_is_waiting().
diffstat:
3 files changed, 29 insertions(+), 2 deletions(-)
src/lib/istream-tee.c | 12 ++++++++++++
src/lib/istream-tee.h | 3 +++
src/lib/test-istream-tee.c | 16 ++++++++++++++--
diffs (106 lines):
diff -r b79bc02aec6d -r 9d878b1dc028 src/lib/istream-tee.c
--- a/src/lib/istream-tee.c Mon Nov 23 15:01:45 2009 -0500
+++ b/src/lib/istream-tee.c Mon Nov 23 15:42:55 2009 -0500
@@ -16,6 +16,8 @@ struct tee_child_istream {
struct tee_istream *tee;
struct tee_child_istream *next;
+
+ unsigned int last_read_waiting:1;
};
static void tee_streams_update_buffer(struct tee_istream *tee)
@@ -112,6 +114,7 @@ static ssize_t i_stream_tee_read(struct
uoff_t last_high_offset;
ssize_t ret;
+ tstream->last_read_waiting = FALSE;
if (stream->buffer == NULL) {
/* initial read */
tee_streams_update_buffer(tstream->tee);
@@ -133,6 +136,7 @@ static ssize_t i_stream_tee_read(struct
if (ret == -2 && stream->skip != 0) {
/* someone else is holding the data,
wait for it */
+ tstream->last_read_waiting = TRUE;
return 0;
}
stream->istream.stream_errno = input->stream_errno;
@@ -212,3 +216,11 @@ struct istream *tee_i_stream_create_chil
return i_stream_create(&tstream->istream, NULL,
i_stream_get_fd(tee->input));
}
+
+bool tee_i_stream_child_is_waiting(struct istream *input)
+{
+ struct tee_child_istream *tstream =
+ (struct tee_child_istream *)input->real_stream;
+
+ return tstream->last_read_waiting;
+}
diff -r b79bc02aec6d -r 9d878b1dc028 src/lib/istream-tee.h
--- a/src/lib/istream-tee.h Mon Nov 23 15:01:45 2009 -0500
+++ b/src/lib/istream-tee.h Mon Nov 23 15:42:55 2009 -0500
@@ -8,6 +8,9 @@
If the stream's buffer gets full because some child isn't consuming the
data, other streams get returned 0 by i_stream_read(). */
struct tee_istream *tee_i_stream_create(struct istream *input);
+/* Returns TRUE if last read() operation returned 0, because it was waiting
+ for another tee stream to read more of its data. */
+bool tee_i_stream_child_is_waiting(struct istream *input);
struct istream *tee_i_stream_create_child(struct tee_istream *tee);
diff -r b79bc02aec6d -r 9d878b1dc028 src/lib/test-istream-tee.c
--- a/src/lib/test-istream-tee.c Mon Nov 23 15:01:45 2009 -0500
+++ b/src/lib/test-istream-tee.c Mon Nov 23 15:42:55 2009 -0500
@@ -30,7 +30,9 @@ static void test_istream_tee_tailing(con
test_istream_set_size(test_input, len);
for (i = 0; i < CHILD_COUNT; i++) {
test_assert(i_stream_read(child_input[i]) == 1);
+ test_assert(!tee_i_stream_child_is_waiting(child_input[i]));
test_assert(i_stream_read(child_input[i]) == 0);
+ test_assert(!tee_i_stream_child_is_waiting(child_input[i]));
}
}
@@ -38,27 +40,37 @@ static void test_istream_tee_tailing(con
for (i = 0; i < CHILD_COUNT; i++) {
test_assert(i_stream_read(child_input[i]) == 1);
test_assert(i_stream_read(child_input[i]) == -2);
+ test_assert(!tee_i_stream_child_is_waiting(child_input[i]));
}
for (len++; len <= TEST_STR_LEN; len++) {
test_istream_set_size(test_input, len);
- for (i = 0; i < CHILD_COUNT; i++)
+ for (i = 0; i < CHILD_COUNT; i++) {
test_assert(i_stream_read(child_input[i]) == -2);
+ test_assert(!tee_i_stream_child_is_waiting(child_input[i]));
+ }
for (i = 0; i < CHILD_COUNT-1; i++) {
i_stream_skip(child_input[i], 1);
test_assert(i_stream_read(child_input[i]) == 0);
+ test_assert(tee_i_stream_child_is_waiting(child_input[i]));
}
i_stream_skip(child_input[i], 1);
for (i = 0; i < CHILD_COUNT; i++) {
test_assert(i_stream_read(child_input[i]) == 1);
test_assert(i_stream_read(child_input[i]) == -2);
+ test_assert(!tee_i_stream_child_is_waiting(child_input[i]));
}
}
- for (i = 0; i < CHILD_COUNT; i++) {
+ for (i = 0; i < CHILD_COUNT-1; i++) {
i_stream_skip(child_input[i], 1);
test_assert(i_stream_read(child_input[i]) == 0);
+ test_assert(tee_i_stream_child_is_waiting(child_input[i]));
}
+ i_stream_skip(child_input[i], 1);
+ test_assert(i_stream_read(child_input[i]) == 0);
+ test_assert(!tee_i_stream_child_is_waiting(child_input[i]));
+
test_istream_set_allow_eof(test_input, TRUE);
for (i = 0; i < CHILD_COUNT; i++) {
test_assert(i_stream_read(child_input[i]) == -1);
More information about the dovecot-cvs
mailing list