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

Don't try to fill up the entire buffer on a read. #5

Merged
merged 1 commit into from Oct 15, 2015

Conversation

bvinc83
Copy link
Contributor

@bvinc83 bvinc83 commented Oct 15, 2015

An LZ4 frame is designed so that partial blocks can be "flushed" by
the encoder at any time. A frame can be a long term stream sent over
a network connection. The decoder needs to be sure that it only calls
the underlying read once at a time, when necessary, and be able to
return partially filled buffers. This allows the caller to respond
to flushed data without the decoder blocking on a network read.

An LZ4 frame is designed so that partial blocks can be "flushed" by
the encoder at any time.  A frame can be a long term stream sent over
a network connection.  The decoder needs to be sure that it only calls
the underlying read once at a time, when necessary, and be able to
return partially filled buffers.  This allows the caller to respond
to flushed data without the decoder blocking on a network read.
@bvinc83
Copy link
Contributor Author

bvinc83 commented Oct 15, 2015

When I made my last pull request, I was under the assumption that to use lz4 over a network, each individual message would be an lz4 frame.

Upon further investigation, I figured out that the lz4 frame standard is also intended to be used for streaming. An entire long-running network stream should be one giant lz4 frame. Part of the frame standard is the idea that the sender should be able to "flush" it's data at any point in time, and the other side should be able to read it. My change here should allow the other side to actually read and respond to a network message in this way.

The down side is that this change could break people's programs. If people are using lz4-rs and assuming that the read function will never return until the entire buffer is full, this change will break them. Technically though, the contract for std::io::Read includes the possibility of returning early.

bozaro added a commit that referenced this pull request Oct 15, 2015
Don't try to fill up the entire buffer on a read.
@bozaro bozaro merged commit 1ae80c4 into bozaro:master Oct 15, 2015
@bozaro
Copy link
Owner

bozaro commented Oct 15, 2015

Big thanks :)

@bozaro
Copy link
Owner

bozaro commented Oct 15, 2015

Bumped 1.9.131

thoren-d pushed a commit to thoren-d/lz4-rs that referenced this pull request Jun 23, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants