yohg...@ohgaki.net (Yasuo Ohgaki) wrote:

> > Plain file stream reads data by php_stdiop_read()
> >
> > http://lxr.php.net/xref/PHP_5_6/main/streams/plain_wrapper.c#338
> >
> > As you can see there is no way to return errors from it. We need
> > errno like error handling for PHP streams to propagate errors as well
> > as more robust code for unexpected.
> >
> > So answer for 3 is "we need volunteers" for improvement, I suppose.
> > Anyone?
> 
> Since I replied, I'll write an implementation idea.
> 
> We may add "error" and "clear_error" stream ops in php_stream_ops.
> 
[...]
> 
> "error" adds whatever errors from stream to an array.
> "clear_error" cleanups the array when stream is closed.
> There should be an API to get errors in the array.
> 
> This is easy change. Difficult part is making codes more robust against
> unexpected for all streams.

Hi Yasuo,

thank you very much for the reply, I now start understanding better what
happen and why currently i/o cannot be handled in user's space.

Rather than an array of error, which might be quite expensive to handle,
why not a simple "char * lasterror" field added to the stream struct,
normally set to NULL, where a description of the last error occurred may
be stored? The high-level functions, that is PHP fopen, fread, fwrite,
fflush, fseek, fclose, may then check that string and, if set, trigger
E_WARNING with a meaningful message after having reset that string back
to NULL again. Many C libraries already provide such error strings,
starting from the same C strerror().

The same should then be done with the filters, which currently only may
return PSFS_ERR_FATAL, but might have their "char * lasterror" string
too with the same purpose. Knowing the exact reason of the failure is
essential to distinguish, for example, a dead disk drive or corrupted file
system, from a bare file mistakenly opened with the wrong decompressor
or a file which was badly encoded.

Then all the specific stream and filter implementations can be adjusted
to set that error string; for those still not fixed that string remains
NULL and fopen, ferror, etc. will not report the error just as they do
today, and will be fixed later step by step.

Just an idea.

Regards,
 ___ 
/_|_\  Umberto Salsi
\/_\/  www.icosaedro.it


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to