Skip to content

Commit

Permalink
fix(forward): usage of PollFuture
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemeowx2 committed Aug 30, 2023
1 parent b4f4986 commit 5ad4f5e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion rd-std/src/builtin/forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ struct UdpSource {
target: Address,
resolve_interval: Option<Duration>,
resolve_future: PollFuture<Result<SocketAddr, io::ErrorKind>>,
resolved: Option<SocketAddr>,
resolve_at: Option<Instant>,
}

Expand All @@ -187,6 +188,7 @@ impl UdpSource {
resolve_net: resolve_net.clone(),
listen_udp: udp,
resolve_future: PollFuture::new(resolve_target(resolve_net, target.clone())),
resolved: None,
resolve_at: None,
target,
resolve_interval,
Expand All @@ -211,7 +213,14 @@ impl RawUdpSource for UdpSource {
}
}

let to = ready!(self.resolve_future.poll(cx))?;
let to = match self.resolved {
Some(to) => to,
None => {
let to = ready!(self.resolve_future.poll(cx))?;
self.resolved = Some(to);
to
}
};

if self.resolve_at.is_none() {
self.resolve_at = Some(Instant::now());
Expand Down

0 comments on commit 5ad4f5e

Please sign in to comment.