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

controlled_poll Copy trait should be limited to the Result but gets applied to the FnMut #26

Open
kmf-lab opened this issue Dec 15, 2024 · 2 comments

Comments

@kmf-lab
Copy link

kmf-lab commented Dec 15, 2024

Signature looks like this and there should probably be () arround the (Result<ControlledPollAction, AeronError> + Copy)

pub fn controlled_poll(
&mut self,
fragment_handler: impl FnMut(&AtomicBuffer, Index, Index, &Header) -> Result<ControlledPollAction, AeronError> + Copy,
fragment_limit: i32,
) -> i32 {

The handler function can not effectively be both FnMut and Copy

@kmf-lab
Copy link
Author

kmf-lab commented Dec 17, 2024

after working with this I am not sure what the solution is since this function ends up getting used in a loop which is causing a compiler error.

@kmf-lab
Copy link
Author

kmf-lab commented Dec 17, 2024

ok this might be the correct solution. I will be testing it soon: Note that fragment_handler is prefixed with mut plus we make use of the &mut prefix on each call of controlled_poll when we use the fragment handler. Note copy is also removed from the signature.

pub fn controlled_poll(
    &mut self,
    mut fragment_handler: impl FnMut(&AtomicBuffer, Index, Index, &Header) -> Result<ControlledPollAction, AeronError> ,
    fragment_limit: i32,
) -> i32 {
    let image_list = self.image_list.load_mut();

    let mut fragments_read = 0;

    let mut starting_index = self.round_robin_index as usize;
    self.round_robin_index += 1;

    if starting_index >= image_list.len() {
        self.round_robin_index = 0;
        starting_index = 0;
    }

    for i in starting_index..image_list.len() {
        if fragments_read < fragment_limit {
            fragments_read += image_list
                .get_mut(i)
                .expect("Error getting element from Image vec")
                .controlled_poll(&mut fragment_handler, fragment_limit - fragments_read);
        }
    }

    for i in 0..starting_index {
        if fragments_read < fragment_limit {
            fragments_read += image_list
                .get_mut(i)
                .expect("Error getting element from Image vec")
                .controlled_poll(&mut fragment_handler, fragment_limit - fragments_read);
        }
    }

    fragments_read
}

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

1 participant