void FdOutStream::flush()
{
  while (sentUpTo < ptr) {
    int n = writeWithTimeout((const void*) sentUpTo,
                             ptr - sentUpTo,
                             blocking? timeoutms : 0);

    // Timeout?
    if (n == 0) {
      // If non-blocking then we're done here
      if (!blocking)
        break;

      throw TimedOut();
    }

    sentUpTo += n;
    offset += n;
  }

   // Managed to flush everything?
  if (sentUpTo == ptr)
    ptr = sentUpTo = start;
}
The software writes data past the end, or before the beginning, of the intended buffer.