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

fix: cover the zero capacity case of the handlers #1231

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions commons/zenoh-collections/src/ring_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct RingBuffer<T> {
impl<T> RingBuffer<T> {
#[must_use]
pub fn new(capacity: usize) -> RingBuffer<T> {
assert!(capacity > 0, "capacity must be non-zero");
let buffer = VecDeque::<T>::with_capacity(capacity);
RingBuffer {
capacity,
Expand Down
6 changes: 5 additions & 1 deletion zenoh/src/api/handlers/fifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ impl<T: Send + 'static> IntoHandler<'static, T> for FifoChannel {
type Handler = flume::Receiver<T>;

fn into_handler(self) -> (Callback<'static, T>, Self::Handler) {
flume::bounded(self.capacity).into_handler()
if self.capacity == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like implicit behaviour with magic numbers that change the type of the internal channel.
Users can already pass an unbound channel with

session
    .declare_subscriber("myke")
    .with(flume::unbounded())
    .await
    .unwrap();

For the above reason I don't see the need of such change.

flume::unbounded().into_handler()
} else {
flume::bounded(self.capacity).into_handler()
}
}
}

Expand Down