RE: [PHP-GTK] while loop and select
| From: | will at 25sucks dot com | Date: | Sun, 18 Dec 2005 07:13:39 +0000 |
| Subject: | RE: [PHP-GTK] while loop and select | ||
| Groups: | php.gtk.general | ||
| Request: | Send a blank email to php-gtk-general+get-6423@lists.php.net to get a copy of this message | ||
Yeah thanks! that did work. As long as I change my select to poll every
500 usec the gui seems to update pretty smoothly
while (true)
{ $numchanged = select($r,$w=NULL,$e=NULL,0,500);
while (gtk::events_pending()) { gtk::main_iteration(); }
if ($numchanged < 1)
{ continue;
}
//DO STUFF WITH SOCKETS...
}
The cpu's not maxing out, but I'm wondering if this is terribly
inefficient. I did some reading on different socket strategies.
http://tangentsoft.net/wskfaq/articles/io-strategies.html
According to this guide, programs with listening sockets running inside
a GUI should be event driven or "Asynchronous".
I guess that is similar to the behavior of MS's winsock control.
Somehow the gui queries the control looking for a "data_arrived"
signal (just like the "clicked" signal for a button, but originating
from the socket).
I'm relatively new to GTK. Is it possible (it's surely difficult) to
create a custom GTK object that that is queried by the event
handler like any other control, but who's data source is a select()
statement rather than a mouse or click event.?
just wondering
Thanks for the help!
will
> -------- Original Message --------
> Subject: Re: [PHP-GTK] while loop and select
> From: Christian Weiske <cweiske@cweiske.de>
> Date: Sat, December 17, 2005 3:14 am
> To: PHP-Gtk-General <php-gtk-general@lists.php.net>
>
> Will,
>
>
> > But when it gets to the select() the program is blocked from execution
> > while it waits for input and so
> That's exactly the problem with not having threads. The main loop can't
> run while the socket reading function blocks program execution
>
> > GTK gets frozen and cannot redraw I suppose. Then it says "Not
> > Responding" and dies.
> You can use the well-known
> > while (Gtk::events_pending()) { Gtk::main_iteration();}
> *if* the code continues and the socket reading function returns after
> some seconds or so.
> That would be possible:
>
> while(socket_not_closed) {
> read_for_some_milliseconds();
> while (Gtk::events_pending()) { Gtk::main_iteration();}
> }
>
> Just the question where to get the read_for_some_milliseconds() function :)
>
> --
> Regards/MfG,
> Christian Weiske