* fhandler_base.cc (fhandler_base::readv): Rework to properly return number of

bytes from read.
This commit is contained in:
Christopher Faylor 2003-07-28 21:13:17 +00:00
parent df4b5a9c5a
commit d2466c7aa0
2 changed files with 13 additions and 7 deletions

View File

@ -1,3 +1,8 @@
2003-07-28 Christopher Faylor <cgf@redhat.com>
* fhandler_base.cc (fhandler_base::readv): Rework to properly return
number of bytes from read.
2003-07-26 Christopher Faylor <cgf@redhat.com>
* exceptions.cc (ctrl_c_handler): Send SIGHUP when events occur only if

View File

@ -758,28 +758,29 @@ fhandler_base::readv (const struct iovec *const iov, const int iovcnt,
assert (iov);
assert (iovcnt >= 1);
size_t len = tot;
if (iovcnt == 1)
{
size_t len = iov->iov_len;
len = iov->iov_len;
read (iov->iov_base, len);
return len;
}
if (tot == -1) // i.e. if not pre-calculated by the caller.
{
tot = 0;
len = 0;
const struct iovec *iovptr = iov + iovcnt;
do
{
iovptr -= 1;
tot += iovptr->iov_len;
len += iovptr->iov_len;
}
while (iovptr != iov);
}
assert (tot >= 0);
if (tot == 0)
if (!len)
return 0;
char *buf = (char *) alloca (tot);
@ -790,10 +791,10 @@ fhandler_base::readv (const struct iovec *const iov, const int iovcnt,
return -1;
}
read (buf, (size_t) tot);
read (buf, len);
ssize_t nbytes = (ssize_t) len;
const struct iovec *iovptr = iov;
int nbytes = tot;
while (nbytes > 0)
{
@ -804,7 +805,7 @@ fhandler_base::readv (const struct iovec *const iov, const int iovcnt,
nbytes -= frag;
}
return tot;
return len;
}
ssize_t