Check out the new USENIX Web site. next up previous
Next: Asynchronous API example Up: Asynchronous API Previous: The GnomeVFSAsyncHandle object

Opening a file as a GLib I/O channel

A common application case is when the program needs to get data from a file stream as soon as it becomes available from the transport layer. In the case of Unix, this is achieved through the select() system call.

GLib abstracts this mechanism by merging it with the event handling loop, through objects known as GIOChannels. With GIOChannels, it is possible to attach callbacks to a file descriptor, and have functions called as soon as data becomes available on it.

Special GNOME VFS API functions allow the programmer to open and read (or write) a file through a GIOChannel. For example, a file can be opened by using the following function:

 GnomeVFSResult
 gnome_vfs_open_as_channel
   (GnomeVFSAsyncHandle **handle return,
    const gchar *text uri,
    GnomeVFSOpenMode open_mode,
    guint advised_block_size,
    GnomeVFSAsyncOpenAsChannelCallback
      callback,
    gpointer closure);

Notice that, unlike the normal Unix select() call, this is reliable with local files too: the application will never be blocked after reading from a file for which the ``data available'' callback has been called.

This is possible because of the GNOME VFS asynchronous engine described in section 11.


next up previous
Next: Asynchronous API example Up: Asynchronous API Previous: The GnomeVFSAsyncHandle object
Ettore Perazzoli 2000-04-26