Input functions are handled on
the GDK level. They are invoked when a given file
descriptor is ready for reading or writing. They're
especially useful for networked applications.
To add an input function, you specify the file descriptor
to monitor, the state you want to wait for (ready for
reading or writing), and a callback/data pair. Figure 32 shows the
API. Functions can be removed using the tag returned by
gdk_input_add(). Unlike quit,
timeout, and idle functions, it should be safe to call
gdk_input_remove() from inside
the input function; GTK+ will not be in the midst of
iterating over the list of input functions.
To specify the condition(s) to wait for, use the GdkInputCondition flags: GDK_INPUT_READ, GDK_INPUT_WRITE, and GDK_INPUT_EXCEPTION. You can OR one
or more flags together. These correspond to the three
file descriptor sets passed to the
select() system call; consult a good UNIX
programming book for details. If any condition is met,
the input function is invoked.
The callback should look like this:
typedef void (*GdkInputFunction) (gpointer data,
It receives your callback data, the file descriptor being
watched, and the conditions that were met (possibly a
subset of those you were watching for).
gint gdk_input_add(gint source_fd, GdkInputCondition
void gdk_input_remove(gint tag);
Figure 32. Input Functions