15.2. Monitoring IO

A nifty feature of GDK is the ability to have it check for data on a file descriptor for you. This is especially useful for networking applications. The method:

 Gdk::Input#add( source, condition ) { method( 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
Gdk::Input::WRITE
Gdk::Input::EXCEPTION

The first calls your method when there is data ready for reading on your file descriptor. The second, calls your method when the file descriptor is ready for writting.

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

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

Gdk::Input#remove( tag )

Prev Next