You may want to have a look at this:
IO Channels
Probably you will need to read the entire page, etc, but I've used that function before, it's great -- it does not block execution, it monitors a "GIOChannel" (a registered file descriptor) and calls the "GIOfunc" (any function with a specific prototype) when there is data waiting to be read. You may need to use it in the context of a glib event loop, so you will have to study glib a bit which is probably worth it if you are programming on linux, since glib is standard on all normative linux systems and used extensively by it and various standard apps. Alot of useful things in glib.
eg.
Code:
g_io_add_watch_full(remote,2,G_IO_IN,(GIOFunc)sortCall,NULL,NULL);
g_io_add_watch_full(remote,1,G_IO_HUP,(GIOFunc)pipeBroke,NULL,NULL);
This is two watches on the same channel, one to respond to G_IO_IN, and one to G_IO_HUP -- which occurs if a connection unexpectedly breaks.