src/io.cpp
// Generally write() writes everything in one call.  Haven't seen any cases
// that justify the loop I do below.  Could take it out.
Generally write() writes everything in one call.  Haven't seen any cases
that justify the loop I do below.  Could take it out.
Generally write () writes everything in one call . Haven ' t seen any cases that justify the loop I do below . Could take it out .
void Writer::Flush(void) {
  if (buf_ptr_ > buf_.get()) {
    int left_to_write = (int)(buf_ptr_ - buf_.get());
    while (left_to_write > 0) {
      int written = write(fd_, buf_.get(), left_to_write);
      if (written < 0) {
	fprintf(stderr,
		"Error in flush: tried to write %i, return of %i; errno %i; "
		"fd %i\n", left_to_write, written, errno, fd_);
	exit(-1);
      } else if (written == 0) {
	sleep(1);
      }
      left_to_write -= written;
    }
  }
  buf_ptr_ = buf_.get();
}
void Writer :: Flush ( void ) { if ( buf_ptr_ > buf_ . get ( ) ) { int left_to_write = ( int ) ( buf_ptr_ - buf_ . get ( ) ) ; while ( left_to_write > 0 ) { int written = write ( fd_ , buf_ . get ( ) , left_to_write ) ; if ( written < 0 ) { fprintf ( stderr , " " " \n " , left_to_write , written , errno , fd_ ) ; exit ( -1 ) ; } else if ( written == 0 ) { sleep ( 1 ) ; } left_to_write -= written ; } } buf_ptr_ = buf_ . get ( ) ; }
Generally write() writes everything in one call.
Generally write () writes everything in one call .
// Stall for a bit to avoid busy loop