[fpc-pascal] TStream.ReadBuffer doesn't try hard enough to read the requested bytes

Michael Van Canneyt michael at freepascal.org
Sun Jun 16 20:20:31 CEST 2013



On Sun, 16 Jun 2013, Michalis Kamburelis wrote:

> Michael Van Canneyt wrote:
>> The above implementation should not be changed, it is Delphi compatible:
>> TStream.ReadBuffer works on the assumption that Read will always return
>> the amount of bytes requested if they are available.
>> 
>> So, if you want to make changes, there is no reason why TStream.Read
>> should not benefit from 'trying harder', it could try harder to actually
>> get the requested number of bytes from the underlying low-level
>> implementation. Some TStream descendents already work that way
>> (compression, hash, encoding), others don't.
>> 
>> This in turn means that affected TStream descendents such as TFileStream
>> or THandleStream should try harder to read the requested number of
>> bytes, taking into account the
>> specifics of the underlying file/socket/whatever protocol.
>> 
>
> In effect, you want to change all the streams Read method implementation, 
> such that it returns less than requested Count *only* when the stream 
> actually ended...

>
> 2. This would be large work, IMHO... I propose to fix a single 
> TStream.ReadBufffer implementation (well, and TStream.WriteBuffer). You 
> propose to fix Read method in all stream descendants, inside and outside FPC 
> sources.

Yes.

If an implementation of Read does not return the requested data when in fact 
it is available, then the implementation of Read is broken.

Your proposal is a quick and dirty hack that does not address the real problem.

Once more, ReadBuffer operates under the assumption that Read 
returns all requested data. That is what it does: it checks 
that read returns the requested data.


Michael.



More information about the fpc-pascal mailing list