Re: blocked window with connections

From: Date: Mon, 25 Nov 2002 21:41:21 +0000
Subject: Re: blocked window with connections
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-2729@lists.php.net to get a copy of this message
Return to the main loop design, and use "input_add" after you've opened the connection. When data arrives from the server, your function will be called. You will no longer require a "while". Here's some working code from a Freeciv UI that my wife and I have been working on. While it is mainly intended for bidirectional pipes on Linux, you should be able to infer the use of a reader callback function. firepage: this also answers your question of 17th November. # pipe functions, begin operating the subprocess pipe function pipe_begin($text) { global $po, $pi, $fifo; $fifo = '/tmp/fifo.'.posix_getpid(); posix_mkfifo($fifo, 0700); $po = popen($text.' > '.$fifo, "w"); $pi = fopen($fifo, 'r'); socket_set_blocking($pi, FALSE); $gu = Gtk::input_add($pi, GDK_INPUT_READ, "pipe_reader"); } # pipe functions, called by GTK when input arrives. function pipe_reader() { global $pi; $line = fgets($pi, 1024); echo $line; if (feof($pi)) { fclose($pi); return FALSE; } return TRUE; } # pipe functions, send a command to the subprocess via pipe function pipe($text) { global $po; fputs($po, "$text\n"); fflush($po); } # pipe functions, close the pipe, killing the process function pipe_end() { global $po, $fifo; fclose($po); unlink($fifo); } -- James Cameron mailto:quozl@us.netrek.org http://quozl.netrek.org/

« previous php.gtk.general (#2729) next »