/* Returns: the status of the operation: One of #G_IO_STATUS_NORMAL, #G_IO_STATUS_AGAIN, or #G_IO_STATUS_ERROR.  */
GIOStatus g_io_channel_flush(GIOChannel *channel, GError **error)
/* Returns: the status of the operation: One of #G_IO_STATUS_NORMAL, #G_IO_STATUS_AGAIN, or #G_IO_STATUS_ERROR.  */
GIOStatus g_io_channel_flush(GIOChannel *channel, GError **error)
{
  GIOStatus status;
  gsize this_time = 1, bytes_written = 0;
  g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);
  g_return_val_if_fail ((error == NULL) || (*error == NULL), G_IO_STATUS_ERROR);
  if (channel->write_buf == NULL || channel->write_buf->len == 0)
    return G_IO_STATUS_NORMAL;
  do
    {
      g_assert (this_time > 0);
      status = channel->funcs->io_write (channel,
					 channel->write_buf->str + bytes_written,
					 channel->write_buf->len - bytes_written,
					 &this_time, error);
      bytes_written += this_time;
    }
  while ((bytes_written < channel->write_buf->len)
         && (status == G_IO_STATUS_NORMAL));
  g_string_erase (channel->write_buf, 0, bytes_written);
  return status;
}