-use async_std::task;
use log::*;
use crate::Connection;
use async_std::net::{TcpStream, ToSocketAddrs};
impl Connection {
- pub fn tcp_client<A: ToSocketAddrs + std::fmt::Display>(ip_addrs: A) -> anyhow::Result<Self> {
- let stream = task::block_on(TcpStream::connect(&ip_addrs))?;
+ pub async fn tcp_client<A: ToSocketAddrs + std::fmt::Display>(
+ ip_addrs: A,
+ ) -> anyhow::Result<Self> {
+ let stream = TcpStream::connect(&ip_addrs).await?;
info!("Established client TCP connection to {}", ip_addrs);
stream.set_nodelay(true)?;
Self::new(
local_addr,
peer_addr,
- Box::new(stream),
- Box::new(write_stream),
+ Box::pin(stream),
+ Box::pin(write_stream),
)
}
}