Re: threaded network




On Tue, 16 Nov 1999, Aldrin Martoq A. wrote:
> Hi. We are writing an app that reads from a server via a socket.
> 
> We use a primary function that does all the job. But when the program is
> in this function, the program's GUI is freezed until the function ends. I
> would like that the statusbar of the mainapp show some status and progress
> while the program is communicating outside.
>

The simplest solution is to read a fixed number of bytes at a time, 
then do the while(gtk_events_pending())gtk_main_iteration() trick (see
FAQ) in between reads.
 
Of course this breaks if the data stream is slow and you block during one
of the reads. You could set a really short timeout on the socket or
something to avoid this.

> I also looked pthreads, but I'm afraid of going un-portable (The info
> pages talks frecuently about linux specific issues). What should I use for
> this task?
> 

pthreads are reasonably portable to modern UNIX flavors, though not
super-portable. There's no really, really portable way to do threads. One
option might be the NSPR (netscape portable runtime) or a similar library.

You could just use a separate process, though this raises the new problem
of how to get the data from one process to the other it shouldn't be all
that hard. You can use input functions (g_io_add_watch()) to communicate
with pipes to coordinate the two processes.

Havoc




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