dj(1): fix inaccurate statistics after Io_read and Io_write

This commit is contained in:
dtb 2024-07-04 20:47:30 -06:00
parent 906eb92f5a
commit 9e8b82c4bb
Signed by: trinity
GPG Key ID: 34C0543BBB6AF81B

View File

@ -69,16 +69,19 @@ static int write_flags = O_WRONLY | O_CREAT;
static struct Io *
Io_read(struct Io *io){
int t;
assert(io->bs > 0);
assert(io->bufuse < io->bs);
io->bytes += (io->bufuse = read(io->fd, &(io->buf)[io->bufuse],
io->bufuse += (t = read(io->fd, &(io->buf)[io->bufuse],
io->bs - io->bufuse));
assert(io->bufuse <= io->bs);
io->prec += (0 < io->bufuse && io->bufuse < io->bs);
io->rec += (io->bufuse == io->bs);
io->bytes += t;
io->prec += (0 < io->bufuse && io->bufuse < io->bs);
io->rec += (io->bufuse == io->bs);
return io;
}
@ -94,8 +97,8 @@ Io_write(struct Io *io){
memmove(io->buf, &(io->buf)[t], (io->bufuse -= t));
io->bytes += t;
io->prec += (t > 0 && io->bufuse > 0);
io->rec += (t > 0 && io->bufuse == 0);
io->prec += (0 < io->bufuse && 0 < t);
io->rec += (io->bufuse == 0 && 0 < t);
return io;
}