RE: [PHP-GTK] Improved socket handling?
| From: | will at 25sucks dot com | Date: | Fri, 16 Dec 2005 23:34:51 +0000 |
| Subject: | RE: [PHP-GTK] Improved socket handling? | ||
| Groups: | php.gtk.general | ||
| Request: | Send a blank email to php-gtk-general+get-6413@lists.php.net to get a copy of this message | ||
This is not a GTK thing is it?
Just use socket select (set ttv_sec & tv_usec = NULL so that it's not
infinitely polling)
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect($sock,$host,$port);
while(true)
{
$r = array($sock)
$numchanged = socket_select($r,$w=NULL,$e=NULL,NULL,NULL);
//THEN DO YOUR CODE HERE AFTER DATA IS AVAILABLE...
//DON'T FORGET TO BUFFER.
}
will
> -------- Original Message --------
> Subject: Re: [PHP-GTK] Improved socket handling?
> From: Andrei Zmievski <andrei@gravitonic.com>
> Date: Fri, December 16, 2005 1:59 pm
> To: lists@benjamindsmith.com
> Cc: php-gtk-general@lists.php.net
>
> Benjamin,
>
> The way this is achieved in Unix is via select(), poll(), kevent(),
> or other methods. There is an pecl/event extension that allows you to
> do this I think, but Gtk+ itself provides support for this via IO
> channels. This is not implemented in PHP-GTK yet, but I will work on it.
>
> -Andrei
>
>
> On Dec 16, 2005, at 10:13 AM, Benjamin Smith wrote:
>
> > What I don't quite understand is that what I suggested initially
> > is exactly
> > now serial communication works! The 16550 UART chip has a buffer in
> > it, and
> > uses a hardware interrupt when the buffer fills. The cpu stops
> > whatever it
> > was doing, handles the data in the buffer, emptying it out.
> >
> > Thus, the serial port can operate more/less independently of the O/
> > S and not
> > tie everything else up while a transfer is underway.
> >
> > But, the use of fopen() and fgets() "linearize" operations, such
> > that when
> > copying data, if nothing comes thru the pipe for a while, the
> > program appears
> > "hung" until either:
> >
> > 1) you use fsockopen() and reach a specified timeout on the
> > connection;
> > 2) The buffer limit specified in fgets() is reached, or
> > 3) When using fgets() on a connection, a newline character comes
> > thru the
> > pipe.
> >
> > I can set the stream to non-blocking mode, and do a loop, but even
> > with that,
> > you're still running a while() loop and that's very resource
> > intensive.
> >
> > So, when doing RPC over TCP, (EG: SOAP/XML, or just retrieving a
> > webpage) the
> > program appears "choppy" and unresponsive.
> >
> > It just seems to me that it should be possble to open a socket,
> > define a
> > callback for the socket, and then have the callback address data
> > when a
> > threshold of input is received, as an event, sort of like a passive
> > fgets().
> >
> > -Ben
> >
> > On Wednesday 14 December 2005 05:37, Christian Weiske wrote:
> >> Hello all,
> >>
> >>> there is another way, you can use gtk :: timeout_add, it will call a
> >>> function(can be from an object) every x miliseconds(seconds?)
> >>> On 12/14/05, Tabber Watts <tabber.watts@gmail.com> wrote:
> >>
> >> That works only if the main loop is running and isn't blocked -
> >> and by
> >> copying the file, it is blocked.
> >>
> >> --
> >> Regards/MfG,
> >> Christian Weiske
> >>
> >
> > --
> > "The best way to predict the future is to invent it."
> > - XEROX PARC slogan, circa 1978
> >
> > --
> > PHP-GTK General Mailing List (http://gtk.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> --
> PHP-GTK General Mailing List (http://gtk.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php