Buffers and Errors

Return to iprintf.

Since iprintf does not return an error code and data is buffered before it is sent, it cannot be assumed that the device received any data after the iprintf has completed. The best way to detect errors is to install your own error handler. This handler can decide the best action to take depending on the error that has occurred.

If an error has occurred during an iprintf with no error handler installed, the only way you can be informed that an error has occurred is to use igeterrno right after the iprintf call. Although iprintf can be called many times without any data being flushed to the session, there are only three (3) conditions where the write formatted I/O buffer is flushed. Those conditions are:

  • If a newline is encountered in the format string.
  • If the buffer is filled.
  • If iflush is called with the I_BUF_WRITE value.

If an error occurs while writing data, such as a timeout, the buffer will be flushed (the data will be lost). If an error handler is installed, it will be called or the error number will be set to the appropriate value.