1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <errno.h>
#include <unistd.h>
#include "obuf.h"
/** Write all pending data in the \c obuf to the file descriptor. */
int obuf_flush(obuf* out)
{
iobuf* io;
unsigned wr;
io = &out->io;
if (iobuf_bad(io)) return 0;
while (io->bufstart < io->buflen) {
if (io->timeout && !iobuf_timeout(io, 1)) return 0;
wr = out->writefn(io->fd, io->buffer+io->bufstart,
io->buflen-io->bufstart);
if (wr == (unsigned)-1) IOBUF_SET_ERROR(io);
io->bufstart += wr;
io->offset += wr;
}
io->buflen = 0;
io->bufstart = 0;
out->bufpos = 0;
return 1;
}
|