-
Notifications
You must be signed in to change notification settings - Fork 55
grant_max returns largest possible buffer #33
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
Conversation
Hey @sjroe, thanks for the PR! I'm inclined to merge this, would you mind expanding the comments for Also, I think it would be worth it to have functions that support both:
and maybe even
I'm open to naming suggestions here. |
Also CC @jonas-schievink for thoughts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, this is definitely the behavior most convenient for me.
|
||
if !self.is_our_grant(&grant.buf) { | ||
panic!("{} {}", sz, start); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems unnecessary since the grant was just created from the right buffer. Maybe replace it with
debug_assert!(self.is_our_grant(&grant.buf));
?
@jamesmunns I'm not averse to creating alternative grant functions but unsure on the naming. Thanks @jonas-schievink - those 3 lines should have been removed; they are remenants of me tracking down an issue. |
@sjroe how about this (feel free to use the descriptions in the comments as well):
|
Also maybe some helpful ascii graphs (I can't remember if the Reader and Writer are allowed to equal eachother, these might need to be tweaked)
|
No problem, I'll look to put all of that together shortly. I'm not keen on the description for
Regarding the test case with 0 bytes comitted, I liked your earlier suggestion of functions as per |
@jamesmunns I implemented the 0 bytes comitted test and it fails for both let bb = bbq!(100).unwrap();
// Grant and commit more than half of the buffer
let wgr = bb.grant(60).unwrap();
bb.commit(60, wgr);
// And release all but one
let rgr = bb.read().unwrap();
assert_eq!(rgr.len(), 60);
bb.release(59, rgr);
// Request grant where there is enough room if invert
let wgr = bb.grant(55).unwrap();
assert_eq!(wgr.len(), 55);
// Commit 0 bytes
bb.commit(0, wgr);
// Release the remaining one byte from the original commit
let rgr = bb.read().unwrap();
assert_eq!(rgr.len(), 1);
bb.release(1, rgr);
// Should now be at position 0 of an empty 100 byte buffer
// Grant and commit to near the end
let wgr = bb.grant(99).unwrap(); // <- fails with Err value: InsufficientSize If using This means that everytime there is a commit < grant size where the grant causes an invert with dead bytes at the end the total usable buffer shrinks. I will track down and resolve but this is a new issue; do you want a separate issue filed? |
@@ -282,24 +282,26 @@ impl BBQueue { | |||
// Inverted, no room is available | |||
return Err(Error::InsufficientSize); | |||
} | |||
} else if write + sz <= max { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using this branch, and it seems that this addition can overflow when passing usize::max()
, which kinda makes sense, but wasn't happening before. This probably isn't a big issue, but still a possibly surprising side-effect.
Hey @sjroe, I know it's been a while, but I'm working on the 0.4.0 release in #37, and I plan to support the following kinds of grants in the future (not all of these may make it into 0.4.0, but should be in 0.4.x releases). Let me know if you think this all makes sense: As a short summary of possible grants:
The following might introduce the concept of "split grants", which provide two
|
Please see #38 for additional work on this topic. |
Resolves #29
grant_max now looks to see if inverting allows the requested (or larger) buffer size to be returned.