Re: threaded network



> 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.

It seems to me that the most logical way of implementing it would be using
threads.  I think the linux-specific pthreads stuff is mostly strange
attributes.
pthread_create(&thread, NULL, proc, data); shouldn't cause any
pthreads-supported platforms.  I have been writing a GNOME app that uses
threads; you can mail me if you need help.

If you really want to avoid threads, you can:
- use the GTK/GNOME nonblocking host lookups and callbacks
- follow with a fork(), in which the child process simply connect()s then
returns(because file descriptors are still shared across a fork, you can
play with sockets)
- finally use the g*_input_add() family to recieve data.
It seems counterintuitive to me, though.

Evan.

--
evan martin - eeyem@u.washington.edu - http://students.washington.edu/eeyem



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]