(
remote_addr: T,
local_addr: Option<SocketAddr>,
ms_timeout: u64,
)
| 81 | |
| 82 | impl FramedStream { |
| 83 | pub async fn new<T: ToSocketAddrs + std::fmt::Display>( |
| 84 | remote_addr: T, |
| 85 | local_addr: Option<SocketAddr>, |
| 86 | ms_timeout: u64, |
| 87 | ) -> ResultType<Self> { |
| 88 | for remote_addr in lookup_host(&remote_addr).await? { |
| 89 | let local = if let Some(addr) = local_addr { |
| 90 | addr |
| 91 | } else { |
| 92 | crate::config::Config::get_any_listen_addr(remote_addr.is_ipv4()) |
| 93 | }; |
| 94 | if let Ok(socket) = new_socket(local, true) { |
| 95 | if let Ok(Ok(stream)) = |
| 96 | super::timeout(ms_timeout, socket.connect(remote_addr)).await |
| 97 | { |
| 98 | stream.set_nodelay(true).ok(); |
| 99 | let addr = stream.local_addr()?; |
| 100 | return Ok(Self( |
| 101 | Framed::new(DynTcpStream(Box::new(stream)), BytesCodec::new()), |
| 102 | addr, |
| 103 | None, |
| 104 | 0, |
| 105 | )); |
| 106 | } |
| 107 | } |
| 108 | } |
| 109 | bail!(format!("Failed to connect to {remote_addr}")); |
| 110 | } |
| 111 | |
| 112 | pub async fn connect<'t, T>( |
| 113 | target: T, |
nothing calls this directly
no test coverage detected