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

Add a next_with_timeout method to DataLinkReciever #650

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AJMansfield
Copy link
Contributor

One attempt at adding a way to do per-call timeouts on DataLinkReciever.
I added it this way for symmetry with the similarly-named TransportChannel methods, though I'm not sure if this is really the best way to do this; perhaps it would be better to just add a set_timeout method?

@mrmonday
Copy link
Contributor

I think a set_timeout() would be better, yes. Or possibly just an entry in the Config struct?

@AJMansfield
Copy link
Contributor Author

I think a set_timeout() would be better, yes. Or possibly just an entry in the Config struct?

That does probably fit better with the design of the library; and I'll happily port my application code to use wrappers around that abstraction if it's added upstream instead of using my own fork.

Just to show how I'm using next_with_timeout from my fork, though, I use it specifically for a single-threaded multiplexed eventloop idiom (e.g. the type of eventloop calls like select(2) exist for in C).
With this specific minimal example being to re-transmit packets after a delay:

loop {
    let rx_result = match tx_queue.do_delayed_retransmit(Instant::now()) // also returns tx time for the next packet after
            .map(|t| t.saturating_duration_since(Instant::now())) // how far in the future is that?
        { 
            Some(sleep) => rx.next_with_timeout(sleep), // sleep at most that long, don't miss the next tx time
            None => rx.next(), // sleep as long as possible, there's no next tx
        }.map(|pkt| (pkt, Instant::now())); // TODO: use SO_TIMESTAMP instead to get the packet timestamp from the kernel

    match rx_result {
        Ok((packet, now)) => tx_queue.schedule_delayed_retransmit(packet, now + delay),
        Err(ref err) if err.kind() == std::io::ErrorKind::TimedOut => {},
        Err(e) => panic!("Error recieving packet: {}", e),
    }
}

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