mirror of
https://github.com/async-rs/async-std.git
synced 2025-01-16 10:49:55 +00:00
replace std::net::ToSocketAddrs
with async-std::net::ToSocketAddrs
This commit is contained in:
parent
d5e8d11fb9
commit
798aa19409
3 changed files with 18 additions and 17 deletions
|
@ -1,4 +1,3 @@
|
|||
use std::net::{self, SocketAddr, ToSocketAddrs};
|
||||
use std::pin::Pin;
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
@ -8,6 +7,7 @@ use super::TcpStream;
|
|||
use crate::future::Future;
|
||||
use crate::io;
|
||||
use crate::net::driver::IoHandle;
|
||||
use crate::net::{SocketAddr, ToSocketAddrs};
|
||||
use crate::task::{Context, Poll};
|
||||
|
||||
/// A TCP socket server, listening for connections.
|
||||
|
@ -84,7 +84,7 @@ impl TcpListener {
|
|||
pub async fn bind<A: ToSocketAddrs>(addrs: A) -> io::Result<TcpListener> {
|
||||
let mut last_err = None;
|
||||
|
||||
for addr in addrs.to_socket_addrs()? {
|
||||
for addr in addrs.to_socket_addrs().await? {
|
||||
match mio::net::TcpListener::bind(&addr) {
|
||||
Ok(mio_listener) => {
|
||||
#[cfg(unix)]
|
||||
|
@ -241,9 +241,9 @@ impl<'a> futures::Stream for Incoming<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<net::TcpListener> for TcpListener {
|
||||
impl From<std::net::TcpListener> for TcpListener {
|
||||
/// Converts a `std::net::TcpListener` into its asynchronous equivalent.
|
||||
fn from(listener: net::TcpListener) -> TcpListener {
|
||||
fn from(listener: std::net::TcpListener) -> TcpListener {
|
||||
let mio_listener = mio::net::TcpListener::from_std(listener).unwrap();
|
||||
|
||||
#[cfg(unix)]
|
||||
|
@ -284,7 +284,7 @@ cfg_if! {
|
|||
|
||||
impl FromRawFd for TcpListener {
|
||||
unsafe fn from_raw_fd(fd: RawFd) -> TcpListener {
|
||||
net::TcpListener::from_raw_fd(fd).into()
|
||||
std::net::TcpListener::from_raw_fd(fd).into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use std::io::{IoSlice, IoSliceMut};
|
||||
use std::mem;
|
||||
use std::net::{self, SocketAddr, ToSocketAddrs};
|
||||
use std::pin::Pin;
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
@ -9,6 +8,7 @@ use futures::io::{AsyncRead, AsyncWrite};
|
|||
|
||||
use crate::io;
|
||||
use crate::net::driver::IoHandle;
|
||||
use crate::net::{SocketAddr, ToSocketAddrs};
|
||||
use crate::task::{Context, Poll};
|
||||
|
||||
/// A TCP stream between a local and a remote socket.
|
||||
|
@ -88,7 +88,7 @@ impl TcpStream {
|
|||
|
||||
let mut last_err = None;
|
||||
|
||||
for addr in addrs.to_socket_addrs()? {
|
||||
for addr in addrs.to_socket_addrs().await? {
|
||||
let mut state = {
|
||||
match mio::net::TcpStream::connect(&addr) {
|
||||
Ok(mio_stream) => {
|
||||
|
@ -444,9 +444,9 @@ impl AsyncWrite for &TcpStream {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<net::TcpStream> for TcpStream {
|
||||
impl From<std::net::TcpStream> for TcpStream {
|
||||
/// Converts a `std::net::TcpStream` into its asynchronous equivalent.
|
||||
fn from(stream: net::TcpStream) -> TcpStream {
|
||||
fn from(stream: std::net::TcpStream) -> TcpStream {
|
||||
let mio_stream = mio::net::TcpStream::from_stream(stream).unwrap();
|
||||
|
||||
#[cfg(unix)]
|
||||
|
@ -487,7 +487,7 @@ cfg_if! {
|
|||
|
||||
impl FromRawFd for TcpStream {
|
||||
unsafe fn from_raw_fd(fd: RawFd) -> TcpStream {
|
||||
net::TcpStream::from_raw_fd(fd).into()
|
||||
std::net::TcpStream::from_raw_fd(fd).into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use std::io;
|
||||
use std::net::{self, Ipv4Addr, Ipv6Addr, SocketAddr, ToSocketAddrs};
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use futures::future;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
|
||||
use crate::net::addr::{SocketAddr, ToSocketAddrs};
|
||||
use crate::net::driver::IoHandle;
|
||||
use crate::task::Poll;
|
||||
|
||||
|
@ -77,7 +78,7 @@ impl UdpSocket {
|
|||
pub async fn bind<A: ToSocketAddrs>(addr: A) -> io::Result<UdpSocket> {
|
||||
let mut last_err = None;
|
||||
|
||||
for addr in addr.to_socket_addrs()? {
|
||||
for addr in addr.to_socket_addrs().await? {
|
||||
match mio::net::UdpSocket::bind(&addr) {
|
||||
Ok(mio_socket) => {
|
||||
#[cfg(unix)]
|
||||
|
@ -156,7 +157,7 @@ impl UdpSocket {
|
|||
/// # Ok(()) }) }
|
||||
/// ```
|
||||
pub async fn send_to<A: ToSocketAddrs>(&self, buf: &[u8], addrs: A) -> io::Result<usize> {
|
||||
let addr = match addrs.to_socket_addrs()?.next() {
|
||||
let addr = match addrs.to_socket_addrs().await?.next() {
|
||||
Some(addr) => addr,
|
||||
None => {
|
||||
return Err(io::Error::new(
|
||||
|
@ -243,7 +244,7 @@ impl UdpSocket {
|
|||
pub async fn connect<A: ToSocketAddrs>(&self, addrs: A) -> io::Result<()> {
|
||||
let mut last_err = None;
|
||||
|
||||
for addr in addrs.to_socket_addrs()? {
|
||||
for addr in addrs.to_socket_addrs().await? {
|
||||
match self.io_handle.get_ref().connect(addr) {
|
||||
Ok(()) => return Ok(()),
|
||||
Err(err) => last_err = Some(err),
|
||||
|
@ -516,9 +517,9 @@ impl UdpSocket {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<net::UdpSocket> for UdpSocket {
|
||||
impl From<std::net::UdpSocket> for UdpSocket {
|
||||
/// Converts a `std::net::UdpSocket` into its asynchronous equivalent.
|
||||
fn from(socket: net::UdpSocket) -> UdpSocket {
|
||||
fn from(socket: std::net::UdpSocket) -> UdpSocket {
|
||||
let mio_socket = mio::net::UdpSocket::from_socket(socket).unwrap();
|
||||
|
||||
#[cfg(unix)]
|
||||
|
@ -559,7 +560,7 @@ cfg_if! {
|
|||
|
||||
impl FromRawFd for UdpSocket {
|
||||
unsafe fn from_raw_fd(fd: RawFd) -> UdpSocket {
|
||||
net::UdpSocket::from_raw_fd(fd).into()
|
||||
std::net::UdpSocket::from_raw_fd(fd).into()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue