Re: threaded network
- From: Roberto Zunino <zunino cli di unipi it>
- To: Evan Martin <eeyem u washington edu>
- cc: Gnome Devel List <gnome-devel-list gnome org>, NotZed <zucchi zedzone mmc com au>
- Subject: Re: threaded network
- Date: Tue, 16 Nov 1999 11:59:05 +0100 (MET)
On Mon, 15 Nov 1999, Evan Martin wrote:
> > Wouldn't it be a lot easier/more reliable ot use a gdk_input handler
> > to call a callback when there actually is data ready, and to use a
> > non-blocking socket read? (or whatever the equivalent glib
> > function is these days == of gdk_input_add) - sockets are fd's too.
> >
> > Michael
>
> It will still block on other network operations. gethostbyname() and
> connect() come to mind.
>
> I recall some sort of support for non-blocking host lookups in either GTK or
> GNOME (which use callbacks), but connect() will still have the problem.
A few months ago I believed you must block for any network operation. Then
I discovered it's possible to do async handling of them for nearly every
operation (even connect!) :-)
I don't go into the details, but it's possible to do connect,accept, and
normal I/O without polling using file descriptors and select()/poll()
calls. this means that _all_ network stuff is doable in a clean way
_except_ (sigh!) AFAIK dns lookup.
If you want a code example you can look at
http://www.cli.di.unipi.it/~zunino/gnome-socket.[ch]
It's only an hack, but it shows how to do basic network things without
blocking. This includes connect(), accept(), read/write, and dns lookup
(but via the deprecated gnome_dns). BTW, the example uses glib's
IOChannels but you could want to use normal file descriptors: in this case
see gdk_input_add() and friends.
For more info read the man pages for accept and connect esp. searching for
"select": you will find the POSIX (I believe) way to do it.
"info libc" is also useful in the socket part.
I keep saying to me "You must put this in glib, you must put this ...".
Hope this helps,
Zun.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]