Re: Streams: Further considerations
| From: | Wez Furlong | Date: | Fri, 04 Oct 2002 21:22:13 +0000 |
| Subject: | Re: Streams: Further considerations | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-89033@lists.php.net to get a copy of this message | ||
That's pretty much what streams was doing a couple of weeks ago.
The reason it was changed was because the stdio fgets doesn't handle
non-native EOL conventions :-/.
What are your thoughts on the following:
- Disable buffering for stdio streams (setvbuf(3) or similar).
- read(2) using the fd obtained from fileno(3) (where valid).
The stdio buffering could be restored when the stream is cast
for use by third-party libraries.
--Wez.
On 10/04/02, "Sascha Schumann" <sascha@apache.org> wrote:
> 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