gtk::input_add not useful, except for sockets
| From: | James Cameron | Date: | Fri, 06 Dec 2002 11:57:59 +0000 |
| Subject: | gtk::input_add not useful, except for sockets | ||
| Groups: | php.gtk.general | ||
| Request: | Send a blank email to php-gtk-general+get-2786@lists.php.net to get a copy of this message | ||
The gtk::input_add implementation in PHP-GTK suffers from standard I/O
buffering, rendering it useless for files, named pipes, and popen()
pipes.
Although the handler for arriving data is called, it can only do
blocking I/O at the standard I/O level; with fgets(). But the handler
is only called when the file descriptor is ready to be read.
What happens is that the marshal function is called by GTK+ once the
select() call indicates that the file descriptor is readable. The
user program PHP handler will call fgets(), which must read() to fill
the buffer. This read() may clear the readability state of the file
descriptor. The handler will not be called again until more data has
arrived, despite the data yet to be read in the standard I/O buffer
used by fgets().
The result from the PHP programmer's perspective is that lines from the
pipe, fifo, or file are held up, and may not arrive at all.
Possible solutions that I can see:
1) PHP to implement a non-blocking fgets(),
2) PHP to implement an fread() of pipes,
3) PHP or PHP-GTK to set pipe FILE * to be line buffered, mit setvbuf()
4) PHP-GTK to re-call the handler until stream buffer empty,
(but how to tell if a standard I/O stream buffer has data?)
Workarounds available to the programmer above PHP-GTK:
5) use unix domain socket instead of popen(),
6) use AF_INET TCP socket instead of popen().
These workarounds should work because the socket can be set non-
blocking, and reading the socket might not necessarily involve standard
I/O buffering.
Could I have a technical review of the above, please?
--
James Cameron mailto:quozl@us.netrek.org http://quozl.netrek.org/