-
Notifications
You must be signed in to change notification settings - Fork 41
Description
(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?