Re: async file i/o
- From: Havoc Pennington <hp redhat com>
- To: Michael Rothwell <rothwell holly-springs nc us>
- Cc: David Helder <dhelder umich edu>, gtk-app-list <gtk-app-devel-list gnome org>
- Subject: Re: async file i/o
- Date: 16 Jan 2001 14:41:48 -0500
Michael Rothwell <rothwell holly-springs nc us> writes:
David Helder wrote:
O_NONBLOCK should work. E.g.:
state->fd = open (state->pathname, O_RDONLY | O_NONBLOCK);
Then you can use select() or create an IOChannel from the file handle and
use g_io_channel_add_watch().
I just wrote a small program using glade to read a file from a floppy in
4096 byte chunks, using O_NONBLOCK and GIOChannel. It blocks. :(
If you use the main loop (g_io_channel_add_watch(), g_main_run() or
gtk_main()), then O_NONBLOCK isn't needed, because read() won't block
as long as at least one byte is available for reading; your GIOFunc
callback will only be invoked by the main loop if there's at least one
byte.
I think fread() on the other hand will always block, though I could be
wrong.
Of course the main-loop-async may not be what you want, if you want
threads then GIOChannel isn't going to get you anywhere.
Still, O_NONBLOCK should work I think, are you sure you are blocking
on the file descriptor? (see strace output) - maybe you are just
busy-looping by not checking for EAGAIN?
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]