Mercurial > dovecot > core-2.2
changeset 3623:085ebc6e341c HEAD
Use IOV_MAX instead of UIO_MAXIOV when available.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 27 Sep 2005 22:49:59 +0300 |
parents | b402cc8a5d44 |
children | d53d0de2ffbb |
files | src/lib/compat.h src/lib/ostream-file.c |
diffstat | 2 files changed, 26 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/compat.h Tue Sep 27 00:00:08 2005 +0300 +++ b/src/lib/compat.h Tue Sep 27 22:49:59 2005 +0300 @@ -93,6 +93,18 @@ }; #endif +/* IOV_MAX should be in limits.h nowadays. Linux still (2005) requires + defining _XOPEN_SOURCE to get that value. UIO_MAXIOV works with it though, + so use it instead. 16 is the lowest acceptable value for all OSes. */ +#ifndef IOV_MAX +# include <sys/uio.h> +# ifdef UIO_MAXIOV +# define IOV_MAX UIO_MAXIOV +# else +# define IOV_MAX 16 +# endif +#endif + #ifndef HAVE_WRITEV # define writev my_writev struct iovec;
--- a/src/lib/ostream-file.c Tue Sep 27 00:00:08 2005 +0300 +++ b/src/lib/ostream-file.c Tue Sep 27 22:49:59 2005 +0300 @@ -17,10 +17,6 @@ # include <sys/uio.h> #endif -#ifndef UIO_MAXIOV -# define UIO_MAXIOV 16 -#endif - /* try to keep the buffer size within 4k..128k. ReiserFS may actually return 128k as optimal size. */ #define DEFAULT_OPTIMAL_BLOCK_SIZE 4096 @@ -137,22 +133,22 @@ ret = write(fstream->fd, iov->iov_base, iov->iov_len); else { sent = 0; - while (iov_size > UIO_MAXIOV) { + while (iov_size > IOV_MAX) { size = 0; - for (i = 0; i < UIO_MAXIOV; i++) + for (i = 0; i < IOV_MAX; i++) size += iov[i].iov_len; ret = writev(fstream->fd, (const struct iovec *)iov, - UIO_MAXIOV); + IOV_MAX); if (ret != (ssize_t)size) break; sent += ret; - iov += UIO_MAXIOV; - iov_size -= UIO_MAXIOV; + iov += IOV_MAX; + iov_size -= IOV_MAX; } - if (iov_size <= UIO_MAXIOV) { + if (iov_size <= IOV_MAX) { ret = writev(fstream->fd, (const struct iovec *)iov, iov_size); } @@ -163,6 +159,7 @@ if (ret < 0) { if (errno == EAGAIN || errno == EINTR) return 0; + if (errno == EINVAL) i_error("o_stream_sendv() -> EINVAL"); fstream->ostream.ostream.stream_errno = errno; stream_closed(fstream); return -1; @@ -285,6 +282,7 @@ if (offset > OFF_T_MAX) { stream->ostream.stream_errno = EINVAL; + i_error("_seek(1) -> EINVAL"); return -1; } @@ -293,11 +291,13 @@ ret = lseek(fstream->fd, (off_t)offset, SEEK_SET); if (ret < 0) { + if (errno == EINVAL) i_error("_seek(2) -> EINVAL"); stream->ostream.stream_errno = errno; return -1; } if (ret != (off_t)offset) { + i_error("_seek(3) -> EINVAL"); stream->ostream.stream_errno = EINVAL; return -1; } @@ -507,6 +507,7 @@ break; } + if (errno == EINVAL) i_error("io_stream_sendfile() -> EINVAL"); outstream->ostream.stream_errno = errno; if (errno != EINVAL) { /* close only if error wasn't because @@ -656,6 +657,7 @@ ret = write_full(foutstream->fd, data, size); if (ret < 0) { /* error */ + if (errno == EINVAL) i_error("copy backwards -> EINVAL"); outstream->ostream.stream_errno = errno; return -1; } @@ -674,6 +676,7 @@ st = i_stream_stat(instream); if (st == NULL) { + if (errno == EINVAL) i_error("_send_istream() / stat -> EINVAL"); outstream->ostream.stream_errno = instream->stream_errno; return -1; } @@ -689,6 +692,7 @@ /* copying data within same fd. we'll have to be careful with seeks and overlapping writes. */ if (in_size == (uoff_t)-1) { + i_error("_send_istream() / in_size == -1 -> EINVAL"); outstream->ostream.stream_errno = EINVAL; return -1; }