-
Notifications
You must be signed in to change notification settings - Fork 1k
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
transports/tcp: Update if-watch to v3.0.0
#3101
Changes from 4 commits
14978dd
1aa13fa
a1d9391
ab1a9ae
0751a16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,6 +28,8 @@ pub mod tokio; | |||||
|
||||||
use futures::future::BoxFuture; | ||||||
use futures::io::{AsyncRead, AsyncWrite}; | ||||||
use futures::Stream; | ||||||
use if_watch::{IfEvent, IpNet}; | ||||||
use std::net::{SocketAddr, TcpListener, TcpStream}; | ||||||
use std::task::{Context, Poll}; | ||||||
use std::{fmt, io}; | ||||||
|
@@ -46,6 +48,14 @@ pub trait Provider: Clone + Send + 'static { | |||||
type Stream: AsyncRead + AsyncWrite + Send + Unpin + fmt::Debug; | ||||||
/// The type of TCP listeners obtained from [`Provider::new_listener`]. | ||||||
type Listener: Send + Unpin; | ||||||
/// The type of IfWatcher obtained from [`Provider::new_if_watcher`]. | ||||||
type IfWatcher: Stream<Item = io::Result<IfEvent>> + Send + Unpin; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Is this legal Rust? My brain compiler is unsure but it could avoid the need for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is legal syntax, but neither IfWatcher implementation implements this trait, plus There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah damn! The naming of Thanks for checking! |
||||||
|
||||||
/// Create a new IfWatcher responsible for detecting IP address changes. | ||||||
fn new_if_watcher() -> io::Result<Self::IfWatcher>; | ||||||
|
||||||
/// An iterator over all currently discovered addresses. | ||||||
fn addrs(_: &Self::IfWatcher) -> Vec<IpNet>; | ||||||
|
||||||
/// Creates a new listener wrapping the given [`TcpListener`] that | ||||||
/// can be polled for incoming connections via [`Self::poll_accept()`]. | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
|
||
use super::{Incoming, Provider}; | ||
|
||
use async_io_crate::Async; | ||
use async_io::Async; | ||
use futures::future::{BoxFuture, FutureExt}; | ||
use std::io; | ||
use std::net; | ||
|
@@ -55,6 +55,15 @@ pub enum Tcp {} | |
impl Provider for Tcp { | ||
type Stream = Async<net::TcpStream>; | ||
type Listener = Async<net::TcpListener>; | ||
type IfWatcher = if_watch::smol::IfWatcher; | ||
|
||
fn new_if_watcher() -> io::Result<Self::IfWatcher> { | ||
Self::IfWatcher::new() | ||
} | ||
|
||
fn addrs(if_watcher: &Self::IfWatcher) -> Vec<if_watch::IpNet> { | ||
if_watcher.iter().copied().collect() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning the iterator would be possible using a HRTB, but given that this is only called in a rare error path I opted for the simpler approach. |
||
} | ||
|
||
fn new_listener(l: net::TcpListener) -> io::Result<Self::Listener> { | ||
Async::new(l) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switching to
dep:tokio
style as was done in other crates — let me know if this one was deliberately left unchanged