Skip to content

io::Reader for TcpSocketBuf is inconsistent in its implementation of read_byte() and eof() #3891

Description

@am0d

Firstly, this eof() always returns false. While it is understandable due to the way it has been implemented, this is incorrect behaviour. read(...) for the same implementation is able to determine when the end-of-file has been reached, and therefore eof() should be able to as well.

Second, read_byte() of this implementation will fail if no data is read from the buffer. While somewhat understandable behaviour, this breaks the use of ReaderUtil::read_line(), which calls read_byte() repeatedly until it finds an end-of-line or end-of-file. Looking through other implementations of read_byte() in io.rs, it appears that the standard behaviour is to return -1 when end-of-file has been reached. I suggest that we should do the same here, and assume that we have reached the end of the file when no more bytes are read.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions