Streams: Further considerations
| From: | Sascha Schumann | Date: | Fri, 04 Oct 2002 20:41:13 +0000 |
| Subject: | Streams: Further considerations | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-89032@lists.php.net to get a copy of this message | ||
Streams' gets function does not work with stdio, because it
uses fread(3) instead of fgets(3). Like fill_read_buffer
earlier, fread(3) does not return, unless an error occurs or
the amount of data has been read completely. It is basically
impossible to implement an _efficient_ fgets-like function
using fread(3).
Additionally, stdio does its own buffering -- there is no
reason to add another buffer layer above it. The streams
buffer needs to be disabled, because fgets/fread would
otherwise interact wrongly.
The attached patch does this:
- Disables buffering for stdio using PHP_STREAM_FLAG_NO_BUFFER
- Adds a gets hook to stream ops
- Adds a gets implementation to stdio ops
- Makes stream_gets use that hook, if available
- Inverts the semantic of fill_read_buffer regarding blocking
"make test" and entering data using stdin works.
Comments, please.
- Sascha