From da2aa032ccfa8e7e4a4380ef738014549f4d2c2d Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 27 Jun 2009 21:08:45 -0400 Subject: [PATCH] Added struct istream.readable_fd, which is used to determine if sendfile() can be used. --HG-- branch : HEAD --- src/lib-mail/istream-dot.c | 1 + src/lib-mail/istream-header-filter.c | 1 + src/lib-storage/index/mbox/istream-raw-mbox.c | 1 + src/lib/istream-concat.c | 1 + src/lib/istream-crlf.c | 1 + src/lib/istream-data.c | 1 + src/lib/istream-file.c | 1 + src/lib/istream-limit.c | 1 + src/lib/istream-mmap.c | 1 + src/lib/istream-seekable.c | 1 + src/lib/istream.h | 2 ++ src/lib/ostream-file.c | 2 +- src/plugins/zlib/istream-zlib.c | 3 ++- 13 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib-mail/istream-dot.c b/src/lib-mail/istream-dot.c index 5a779d445b..9171315022 100644 --- a/src/lib-mail/istream-dot.c +++ b/src/lib-mail/istream-dot.c @@ -232,6 +232,7 @@ struct istream *i_stream_create_dot(struct istream *input, bool send_last_lf) dstream->istream.read = i_stream_dot_read; dstream->istream.stat = i_stream_dot_stat; + dstream->istream.istream.readable_fd = FALSE; dstream->istream.istream.blocking = input->blocking; dstream->istream.istream.seekable = FALSE; dstream->send_last_lf = send_last_lf; diff --git a/src/lib-mail/istream-header-filter.c b/src/lib-mail/istream-header-filter.c index 4030de228e..858d661773 100644 --- a/src/lib-mail/istream-header-filter.c +++ b/src/lib-mail/istream-header-filter.c @@ -415,6 +415,7 @@ i_stream_create_header_filter(struct istream *input, mstream->istream.sync = i_stream_header_filter_sync; mstream->istream.stat = i_stream_header_filter_stat; + mstream->istream.istream.readable_fd = FALSE; mstream->istream.istream.blocking = input->blocking; mstream->istream.istream.seekable = input->seekable; diff --git a/src/lib-storage/index/mbox/istream-raw-mbox.c b/src/lib-storage/index/mbox/istream-raw-mbox.c index 556173950f..55eb615b22 100644 --- a/src/lib-storage/index/mbox/istream-raw-mbox.c +++ b/src/lib-storage/index/mbox/istream-raw-mbox.c @@ -438,6 +438,7 @@ i_stream_create_raw_mbox(struct istream *input, const char *path) rstream->istream.sync = i_stream_raw_mbox_sync; rstream->istream.stat = i_stream_raw_mbox_stat; + rstream->istream.istream.readable_fd = input->readable_fd; rstream->istream.istream.blocking = input->blocking; rstream->istream.istream.seekable = input->seekable; diff --git a/src/lib/istream-concat.c b/src/lib/istream-concat.c index d18a455d3d..3438374876 100644 --- a/src/lib/istream-concat.c +++ b/src/lib/istream-concat.c @@ -269,6 +269,7 @@ struct istream *i_stream_create_concat(struct istream *input[]) cstream->istream.seek = i_stream_concat_seek; cstream->istream.stat = i_stream_concat_stat; + cstream->istream.istream.readable_fd = FALSE; cstream->istream.istream.blocking = blocking; cstream->istream.istream.seekable = seekable; return i_stream_create(&cstream->istream, NULL, -1); diff --git a/src/lib/istream-crlf.c b/src/lib/istream-crlf.c index 28d98d342f..50562645b5 100644 --- a/src/lib/istream-crlf.c +++ b/src/lib/istream-crlf.c @@ -151,6 +151,7 @@ i_stream_create_crlf_full(struct istream *input, bool crlf) i_stream_crlf_read_lf; cstream->istream.stat = i_stream_crlf_stat; + cstream->istream.istream.readable_fd = FALSE; cstream->istream.istream.blocking = input->blocking; cstream->istream.istream.seekable = FALSE; return i_stream_create(&cstream->istream, input, diff --git a/src/lib/istream-data.c b/src/lib/istream-data.c index f7b1114443..d493cb7132 100644 --- a/src/lib/istream-data.c +++ b/src/lib/istream-data.c @@ -27,6 +27,7 @@ struct istream *i_stream_create_from_data(const void *data, size_t size) stream->read = i_stream_data_read; stream->seek = i_stream_data_seek; + stream->istream.readable_fd = FALSE; stream->istream.blocking = TRUE; stream->istream.seekable = TRUE; (void)i_stream_create(stream, NULL, -1); diff --git a/src/lib/istream-file.c b/src/lib/istream-file.c index e224dcc00d..e3cd90d9fb 100644 --- a/src/lib/istream-file.c +++ b/src/lib/istream-file.c @@ -162,6 +162,7 @@ struct istream *i_stream_create_fd(int fd, size_t max_buffer_size, fstream->istream.istream.blocking = TRUE; fstream->istream.istream.seekable = TRUE; } + fstream->istream.istream.readable_fd = TRUE; return i_stream_create(&fstream->istream, NULL, fd); } diff --git a/src/lib/istream-limit.c b/src/lib/istream-limit.c index d4f5f4dd69..343d228c85 100644 --- a/src/lib/istream-limit.c +++ b/src/lib/istream-limit.c @@ -138,6 +138,7 @@ struct istream *i_stream_create_limit(struct istream *input, uoff_t v_size) lstream->istream.stat = i_stream_limit_stat; lstream->istream.get_size = i_stream_limit_get_size; + lstream->istream.istream.readable_fd = input->readable_fd; lstream->istream.istream.blocking = input->blocking; lstream->istream.istream.seekable = input->seekable; return i_stream_create(&lstream->istream, input, diff --git a/src/lib/istream-mmap.c b/src/lib/istream-mmap.c index 7a0e259c12..5781697156 100644 --- a/src/lib/istream-mmap.c +++ b/src/lib/istream-mmap.c @@ -219,6 +219,7 @@ struct istream *i_stream_create_mmap(int fd, size_t block_size, mstream->istream.sync = i_stream_mmap_sync; mstream->istream.stat = i_stream_mmap_stat; + mstream->istream.istream.readable_fd = TRUE; mstream->istream.abs_start_offset = start_offset; istream = i_stream_create(&mstream->istream, NULL, fd); istream->mmaped = TRUE; diff --git a/src/lib/istream-seekable.c b/src/lib/istream-seekable.c index 48705743a8..49e3a1622d 100644 --- a/src/lib/istream-seekable.c +++ b/src/lib/istream-seekable.c @@ -319,6 +319,7 @@ i_stream_create_seekable(struct istream *input[], sstream->istream.seek = i_stream_seekable_seek; sstream->istream.stat = i_stream_seekable_stat; + sstream->istream.istream.readable_fd = FALSE; sstream->istream.istream.blocking = blocking; sstream->istream.istream.seekable = TRUE; return i_stream_create(&sstream->istream, NULL, -1); diff --git a/src/lib/istream.h b/src/lib/istream.h index 9c99af2375..bac9ca74b1 100644 --- a/src/lib/istream.h +++ b/src/lib/istream.h @@ -11,6 +11,8 @@ struct istream { unsigned int mmaped:1; /* be careful when copying data */ unsigned int blocking:1; /* read() shouldn't return 0 */ unsigned int closed:1; + unsigned int readable_fd:1; /* fd can be read directly if necessary + (for sendfile()) */ unsigned int seekable:1; /* we can seek() backwards */ unsigned int eof:1; /* read() has reached to end of file (but may still be data available in buffer) */ diff --git a/src/lib/ostream-file.c b/src/lib/ostream-file.c index 6e041fb3b1..a0f3317b28 100644 --- a/src/lib/ostream-file.c +++ b/src/lib/ostream-file.c @@ -856,7 +856,7 @@ static off_t o_stream_file_send_istream(struct ostream_private *outstream, off_t in_abs_offset, ret; int in_fd; - in_fd = i_stream_get_fd(instream); + in_fd = !instream->readable_fd ? -1 : i_stream_get_fd(instream); if (in_fd == foutstream->fd) { /* copying data within same fd. we'll have to be careful with diff --git a/src/plugins/zlib/istream-zlib.c b/src/plugins/zlib/istream-zlib.c index 2a101f2060..69f8c3819e 100644 --- a/src/plugins/zlib/istream-zlib.c +++ b/src/plugins/zlib/istream-zlib.c @@ -237,6 +237,7 @@ struct istream *i_stream_create_zlib(int fd) zstream->istream.istream.seekable = TRUE; } - return i_stream_create(&zstream->istream, NULL, -1); + zstream->istream.istream.readable_fd = FALSE; + return i_stream_create(&zstream->istream, NULL, fd); } #endif -- 2.47.3