2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-04-25 09:46:49 +00:00

switch to async-io

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
This commit is contained in:
Marc-Antoine Perennou 2020-07-15 22:05:28 +02:00
parent 8886039ac5
commit 25e0e1abdc
8 changed files with 20 additions and 18 deletions

View file

@ -24,6 +24,7 @@ rustdoc-args = ["--cfg", "feature=\"docs\""]
[features] [features]
default = [ default = [
"std", "std",
"async-io",
"async-task", "async-task",
"kv-log-macro", "kv-log-macro",
"log", "log",
@ -77,6 +78,7 @@ futures-timer = { version = "3.0.2", optional = true }
surf = { version = "1.0.3", optional = true } surf = { version = "1.0.3", optional = true }
[target.'cfg(not(target_os = "unknown"))'.dependencies] [target.'cfg(not(target_os = "unknown"))'.dependencies]
async-io = { version = "0.1.5", optional = true }
smol = { version = "0.1.17", optional = true } smol = { version = "0.1.17", optional = true }
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]

View file

@ -2,7 +2,7 @@ use std::future::Future;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::pin::Pin; use std::pin::Pin;
use smol::Async; use async_io::Async;
use crate::io; use crate::io;
use crate::net::{TcpStream, ToSocketAddrs}; use crate::net::{TcpStream, ToSocketAddrs};
@ -81,7 +81,7 @@ impl TcpListener {
let addrs = addrs.to_socket_addrs().await?; let addrs = addrs.to_socket_addrs().await?;
for addr in addrs { for addr in addrs {
match Async::<std::net::TcpListener>::bind(&addr) { match Async::<std::net::TcpListener>::bind(addr) {
Ok(listener) => { Ok(listener) => {
return Ok(TcpListener { watcher: listener }); return Ok(TcpListener { watcher: listener });
} }
@ -227,7 +227,7 @@ cfg_unix! {
impl IntoRawFd for TcpListener { impl IntoRawFd for TcpListener {
fn into_raw_fd(self) -> RawFd { fn into_raw_fd(self) -> RawFd {
self.watcher.into_raw_fd() self.watcher.into_inner().unwrap().into_raw_fd()
} }
} }
} }
@ -251,7 +251,7 @@ cfg_windows! {
impl IntoRawSocket for TcpListener { impl IntoRawSocket for TcpListener {
fn into_raw_socket(self) -> RawSocket { fn into_raw_socket(self) -> RawSocket {
self.watcher.into_raw_socket() self.watcher.into_inner().unwrap().into_raw_socket()
} }
} }
} }

View file

@ -2,7 +2,7 @@ use std::io::{IoSlice, IoSliceMut};
use std::net::SocketAddr; use std::net::SocketAddr;
use std::pin::Pin; use std::pin::Pin;
use smol::Async; use async_io::Async;
use crate::io::{self, Read, Write}; use crate::io::{self, Read, Write};
use crate::net::ToSocketAddrs; use crate::net::ToSocketAddrs;
@ -77,7 +77,7 @@ impl TcpStream {
let addrs = addrs.to_socket_addrs().await?; let addrs = addrs.to_socket_addrs().await?;
for addr in addrs { for addr in addrs {
match Async::<std::net::TcpStream>::connect(&addr).await { match Async::<std::net::TcpStream>::connect(addr).await {
Ok(stream) => { Ok(stream) => {
return Ok(TcpStream { return Ok(TcpStream {
watcher: Arc::new(stream), watcher: Arc::new(stream),

View file

@ -2,7 +2,7 @@ use std::io;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::net::{Ipv4Addr, Ipv6Addr}; use std::net::{Ipv4Addr, Ipv6Addr};
use smol::Async; use async_io::Async;
use crate::net::ToSocketAddrs; use crate::net::ToSocketAddrs;
use crate::utils::Context as _; use crate::utils::Context as _;
@ -74,7 +74,7 @@ impl UdpSocket {
let addrs = addrs.to_socket_addrs().await?; let addrs = addrs.to_socket_addrs().await?;
for addr in addrs { for addr in addrs {
match Async::<std::net::UdpSocket>::bind(&addr) { match Async::<std::net::UdpSocket>::bind(addr) {
Ok(socket) => { Ok(socket) => {
return Ok(UdpSocket { watcher: socket }); return Ok(UdpSocket { watcher: socket });
} }
@ -506,7 +506,7 @@ cfg_unix! {
impl IntoRawFd for UdpSocket { impl IntoRawFd for UdpSocket {
fn into_raw_fd(self) -> RawFd { fn into_raw_fd(self) -> RawFd {
self.watcher.into_raw_fd() self.watcher.into_inner().unwrap().into_raw_fd()
} }
} }
} }
@ -530,7 +530,7 @@ cfg_windows! {
impl IntoRawSocket for UdpSocket { impl IntoRawSocket for UdpSocket {
fn into_raw_socket(self) -> RawSocket { fn into_raw_socket(self) -> RawSocket {
self.watcher.into_raw_socket() self.watcher.into_inner().unwrap().into_raw_socket()
} }
} }
} }

View file

@ -4,7 +4,7 @@ use std::fmt;
use std::net::Shutdown; use std::net::Shutdown;
use std::os::unix::net::UnixDatagram as StdUnixDatagram; use std::os::unix::net::UnixDatagram as StdUnixDatagram;
use smol::Async; use async_io::Async;
use super::SocketAddr; use super::SocketAddr;
use crate::io; use crate::io;
@ -335,6 +335,6 @@ impl FromRawFd for UnixDatagram {
impl IntoRawFd for UnixDatagram { impl IntoRawFd for UnixDatagram {
fn into_raw_fd(self) -> RawFd { fn into_raw_fd(self) -> RawFd {
self.watcher.into_raw_fd() self.watcher.into_inner().unwrap().into_raw_fd()
} }
} }

View file

@ -5,7 +5,7 @@ use std::future::Future;
use std::os::unix::net::UnixListener as StdUnixListener; use std::os::unix::net::UnixListener as StdUnixListener;
use std::pin::Pin; use std::pin::Pin;
use smol::Async; use async_io::Async;
use super::SocketAddr; use super::SocketAddr;
use super::UnixStream; use super::UnixStream;
@ -217,6 +217,6 @@ impl FromRawFd for UnixListener {
impl IntoRawFd for UnixListener { impl IntoRawFd for UnixListener {
fn into_raw_fd(self) -> RawFd { fn into_raw_fd(self) -> RawFd {
self.watcher.into_raw_fd() self.watcher.into_inner().unwrap().into_raw_fd()
} }
} }

View file

@ -5,7 +5,7 @@ use std::net::Shutdown;
use std::os::unix::net::UnixStream as StdUnixStream; use std::os::unix::net::UnixStream as StdUnixStream;
use std::pin::Pin; use std::pin::Pin;
use smol::Async; use async_io::Async;
use super::SocketAddr; use super::SocketAddr;
use crate::io::{self, Read, Write}; use crate::io::{self, Read, Write};

View file

@ -61,7 +61,7 @@ pub(crate) trait Context {
#[cfg(all(not(target_os = "unknown"), feature = "default"))] #[cfg(all(not(target_os = "unknown"), feature = "default"))]
mod timer { mod timer {
pub type Timer = smol::Timer; pub type Timer = async_io::Timer;
} }
#[cfg(any(feature = "unstable", feature = "default"))] #[cfg(any(feature = "unstable", feature = "default"))]
@ -69,7 +69,7 @@ pub(crate) fn timer_after(dur: std::time::Duration) -> timer::Timer {
#[cfg(all(not(target_os = "unknown"), feature = "default"))] #[cfg(all(not(target_os = "unknown"), feature = "default"))]
once_cell::sync::Lazy::force(&crate::rt::RUNTIME); once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
Timer::after(dur) Timer::new(dur)
} }
#[cfg(any( #[cfg(any(
@ -84,7 +84,7 @@ mod timer {
pub(crate) struct Timer(futures_timer::Delay); pub(crate) struct Timer(futures_timer::Delay);
impl Timer { impl Timer {
pub(crate) fn after(dur: std::time::Duration) -> Self { pub(crate) fn new(dur: std::time::Duration) -> Self {
Timer(futures_timer::Delay::new(dur)) Timer(futures_timer::Delay::new(dur))
} }
} }