Skip to content

HInputStream should allow a user-supplied read function #181

@puellavulnerata

Description

@puellavulnerata

(per private conversation with mlp, I understand there is an intent to add a capability to read from a file/network connection/etc.; this should be understood in that context as a note on flexibility)

Currently, HInputStream keeps a pointer to an in-memory buffer. It would be better if it could read data as needed into a sliding window / discard as no longer needed at the other end.

  • Additional complication: HInputStream also has a length field; with this approach we may not know the length in advance

When this is implemented, I recommend doing it with a function pointer to a "read n more bytes from the source" function, and wrappers to create a new input stream around a {file descriptor|network connection|etc.}. This way, it will turn out to be flexible enough to accomodate unexpected sources (e.g. connect over SOCKS proxy, need to do protocol first, tunnel inside SSL, need to call SSL_read(), etc.)

See the implementation of the BIO mechanism in OpenSSL for a (somewhat overcomplex) example of this approach, and https://wiki.openssl.org/index.php/Manual:BIO_s_mem%283%29 for its flexibility.

  • Additional consideration here: async I/O?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions