-
Notifications
You must be signed in to change notification settings - Fork 50
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
Add ebuf data structure #1487
Add ebuf data structure #1487
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1487 +/- ##
==========================================
+ Coverage 78.69% 78.78% +0.08%
==========================================
Files 164 165 +1
Lines 30405 30564 +159
==========================================
+ Hits 23928 24079 +151
- Misses 6477 6485 +8
|
Some initial comments, maybe to get discussion going:
|
Sounds like a good idea. I stuck it in libflux somewhat randomly.
I had this at first, but took it out b/c some other buf libs don't have such a configuration. Perhaps I was thinking too far out and we should just add it for the current implementation.
I was not aware of that, so definitely should adjust that. |
Add new event buffer data structure. A generic buffer data structure that can generate events when data is read/written from/to.
re-pushed with adjustments per comments above. Also added a test to check for ENOSPC if writes go above max buffer size. Went ahead and squashed everything since changes are relatively tiny. |
Hit a #1150, re-start a builder. |
Sorry I haven't had another chance to finish a review this yet @chu11. It would be nice if the interface had at least one user before we merge it, but I realize that will be difficult for this particular case, so I'm willing to merge if it helps things move forward. Talking with @garlick and he had a good question about whether a reactor based buffer watcher could be built from this interface. I seem to remember I've had definite opinions on this before, but I'm not remembering the details. At the very least, the simpler ebufs you have here could most likely be used to build buffer watchers, and are easier to unit test. It is also more flexible, because we aren't constrained to the I guess one question is whether a watcher interface for these ebufs would be useful, and if so, does the ebuf interface support it? This could probably use some discussion. |
Yeah, the path between now and #1052 completion isn't 100% in my head at the moment. I think the main steps I had in my head were:
In my mind #1 and #2 are clear, #3 is sort of optional. #4 is the one I can't see clearly. I'm sort of hoping it becomes more clear as this is worked on. As long as you feel |
I prototyped a:
Basically it's a read watcher on a fd, but only calls the callback when a line is ready. I'm not sure the Basically, converting from the ebuf's callback to the user's callback is somewhat cumbersome. You need to stuff whatever you need to carry along in the I think just semi-manually doing a:
would be far easier. Which then begs the question, if I feel the callback mechanisms of |
The other subtlety I realized is that we probably need to have a public facing
set of functions for watchers type. Instead, the user should just call:
and go from there. This is similar to how |
talked to @grondo, since we're going to need a public |
Per discussion in #1052, add a simple buffer api that will execute a callback when data in the buffer goes above/below a certain mark or when a line is ready.
Internally, I use the
cbuf
library. Some API decisions were made under the assumption I may swap outcbuf
for another library in the future (evbuffer
,vrb
etc.).For example, some libraries expose their internal buffers so users can read data without an additional copy.
cbuf
doesn't support this, but I wanted to prepare for a potential future change. Soebuf_read()
presently returns a pointer to a malloced buffer for the user to read from, but does not expect the user to free this pointer.Also, at most one callback is supported right now. I did not want to allow the user to have both read & write callbacks, which could lead to cascading infinite callback calls.