/* write all the data in the buffer to the stream */ int tio_flush(TFILE *fp) { struct timespec deadline = {0, 0}; /* loop until we have written our buffer */ while (fp->writebuffer.len > 0) { /* wait until we can write */ if (tio_wait(fp->fd, POLLOUT, fp->writetimeout, &deadline)) return -1; /* write one block */ if (tio_writebuf(fp)) return -1; } return 0; }
/* write all the data in the buffer to the stream */ int tio_flush(TFILE *fp) { struct timeval deadline; /* build a time by which we should be finished */ tio_get_deadline(&deadline,fp->writetimeout); /* loop until we have written our buffer */ while (fp->writebuffer.len > 0) { /* wait until we can write */ if (tio_wait(fp,0,&deadline)) return -1; /* write one block */ if (tio_writebuf(fp)) return -1; } return 0; }
/* try a single write of data in the buffer if the file descriptor will accept data */ static int tio_flush_nonblock(TFILE *fp) { struct pollfd fds[1]; int rv; /* wait for activity */ fds[0].fd=fp->fd; fds[0].events=POLLOUT; rv=poll(fds,1,0); /* check if any file descriptors were ready (timeout) or we were interrupted */ if ((rv==0)||((rv<0)&&(errno==EINTR))) return 0; /* any other errors? */ if (rv<0) return -1; /* so file descriptor will accept writes */ return tio_writebuf(fp); }
/* try a single write of data in the buffer if the file descriptor will accept data */ static int tio_flush_nonblock(TFILE *fp) { struct timeval tv; fd_set fdset; int rv; /* prepare our filedescriptorset */ FD_ZERO(&fdset); FD_SET(fp->fd,&fdset); /* set the timeout to 0 to poll */ tv.tv_sec=0; tv.tv_usec=0; /* wait for activity */ rv=select(FD_SETSIZE,NULL,&fdset,NULL,&tv); /* check if any file descriptors were ready (timeout) or we were interrupted */ if ((rv==0)||((rv<0)&&(errno==EINTR))) return 0; /* any other errors? */ if (rv<0) return -1; /* so file descriptor will accept writes */ return tio_writebuf(fp); }