Re: Data available for reading in a GIOChannel
- From: Robert Pearce <rob bdt-home demon co uk>
- To: gtk-list gnome org
- Subject: Re: Data available for reading in a GIOChannel
- Date: Mon, 28 May 2007 18:36:43 +0100
On Sun, 27 May 2007 16:57:03 +0200 Jonathan wrote:
> Hi,
>
> I need to read a large amount of data from a GIOChannel (200K, over
> the internet).
>
> So far, I use the gnet library to create the
> socket, and then I use the GIOChannel to integrate the read/writing
> into the program's loop (a
> GTK application)
>
> I use g_io_add_watch(_channel, G_IO_IN, &(_imageDataReadyForReading), this);
> to register the callback for data reading.
>
> How can I determine the number of bytes available for reading, so as not to
> block on reading the data?
>
On the applications where I've used g_io_add_watch it's on a serial port that I've opened non-blocking. Then my callback I just does:
stat = g_io_channel_read_chars ( source,
tmpbuf, sizeof(tmpbuf), &len, &err );
If there are less than tmpbuf characters waiting, it fills what it can and sets len to the actual number. Then I process len bytes. Normally my tmpbuf is bigger than the longest message I expect, but it seems to work even if it isn't.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]