Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HInputStream should allow a user-supplied read function #181

Open
puellavulnerata opened this issue Dec 6, 2016 · 3 comments
Open

HInputStream should allow a user-supplied read function #181

puellavulnerata opened this issue Dec 6, 2016 · 3 comments

Comments

@puellavulnerata
Copy link

(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?
@pesco
Copy link

pesco commented Dec 6, 2016

Have a look at the existing support for incremental parsing via h_parse_start, h_parse_chunk, h_parse_finish! We added and used this for the DNP3 proxy.

@nil-ableton
Copy link

A nice write up on io buffers for layering (say when you have stream sitting on top of a compressed stream, or some other structure)

https://fgiesen.wordpress.com/2011/11/21/buffer-centric-io/

@pesco
Copy link

pesco commented Mar 31, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants