Re: IO Channel Flush - Assertion Failure



The assert only happens if io_write returns a successful status code AND the total bytes_written are less that the bytes in the buffer. So io_write() wrote nothing while there was data to write but did not report an error. That does sound like a bug to me. I bet the bug is in io_write(). It should return an error status if it could not write any more data.

Peter Long

----- Original Message ----
From: Christian Bünnig <masala web de>
To: "gtk-list gnome org" <gtk-list gnome org>
Sent: Tuesday, December 18, 2007 11:52:57 AM
Subject: IO Channel Flush - Assertion Failure


Hi,

for data communication between 2 Bluetooth devices I have created IO
channels on the corresponding sockets. This works well the most time.
However, sometimes (I could not determine the exact occurrence yet)
flushing the channel with g_io_channel_flush() fails in that it raises
an assertion error. The failure happens in the line
  g_assert (this_time > 0);
in the function below (from giochannel.c)

------ snip -------

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); /// THIS ASSERTION FAILS ///

      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;
}

------- snip --------

Afaik. assertions are used to detect bugs .. why is it considered as a
bug if channel->funcs->io_write() writes no data (this_time == 0)? And
who is responsible for that assertion failure?

Thanks for some advice,

Christian

_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]