GTK+ 2.0 Tutorial
<<< Previous | Timeouts, IO and Idle Functions | Next >>>

# Monitoring IO

A nifty feature of GDK (the library that underlies GTK), is the ability to have it check for data on a file descriptor for you (as returned by open(2) or socket(2)). This is especially useful for networking applications. The function:

    gint gdk_input_add( gint              source,
                        GdkInputCondition condition,
                        GdkInputFunction  function,
                        gpointer          data );

Where the first argument is the file descriptor you wish to have watched, and the second specifies what you want GDK to look for. This may be one of:

- `GDK_INPUT_READ` - Call your function when there is data ready for reading on your file descriptor.

- >`GDK_INPUT_WRITE` - Call your function when the file descriptor is ready for writing.

As I'm sure you've figured out already, the third argument is the function you wish to have called when the above conditions are satisfied, and the fourth is the data to pass to this function.

The return value is a tag that may be used to stop GDK from monitoring this file descriptor using the following function.

    void gdk_input_remove( gint tag );

The callback function should be declared as:

    void input_callback( gpointer          data,
                         gint              source,
                         GdkInputCondition condition );

Where `source` and `condition` are as specified above.

<<< Previous | Home | Next >>>
Timeouts, IO and Idle Functions | Up | Idle Functions