diff --git a/Cargo.lock b/Cargo.lock index 1ee1122b9..f788fd5e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,16 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" +[[package]] +name = "async-barrier" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06293698675eb72e1155867e5982f199d6b6c230dca35bc5ffd9852f470c22a" +dependencies = [ + "async-mutex", + "event-listener", +] + [[package]] name = "async-channel" version = "1.4.2" @@ -35,6 +45,114 @@ dependencies = [ "futures-core", ] +[[package]] +name = "async-executor" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a831e74aa1937d3bbd3a356f34c23dbc6b6f0abc5160bd5484a9f75d5e76aea8" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "once_cell", +] + +[[package]] +name = "async-fs" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3572236ba37147ca2b674a0bd5afd20aec0cd925ab125ab6fad6543960f9002" +dependencies = [ + "blocking", + "futures-lite", +] + +[[package]] +name = "async-io" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64c629684e697f58c0e99e5e2d84a840e3b336afbcfdbac7b44c3b1e222c2fd8" +dependencies = [ + "concurrent-queue", + "fastrand", + "futures-lite", + "log", + "nb-connect", + "once_cell", + "parking", + "polling", + "vec-arena", + "waker-fn", +] + +[[package]] +name = "async-lock" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3ad7fb4345397e57c19566844b0eba274b92e5d2d2791bb0664cc441697b95" +dependencies = [ + "async-barrier", + "async-mutex", + "async-rwlock", + "async-semaphore", +] + +[[package]] +name = "async-mutex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66941c2577c4fa351e4ce5fdde8f86c69b88d623f3b955be1bc7362a23434632" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-net" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a48af5438be856056bdeb6c5d895148a715be5915fccee49d1e5b50851dc9b8b" +dependencies = [ + "async-io", + "blocking", + "futures-lite", +] + +[[package]] +name = "async-process" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb915df28b8309139bd9c9c700d84c20e5c21385d05378caa84912332d0f6a1" +dependencies = [ + "async-io", + "blocking", + "cfg-if", + "event-listener", + "futures-lite", + "once_cell", + "signal-hook", + "winapi 0.3.9", +] + +[[package]] +name = "async-rwlock" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f8978b5ae008b5177da07a1bf1bfbe428f9bdb970c3fca0e92ed1c1930d7f34" +dependencies = [ + "async-mutex", + "event-listener", +] + +[[package]] +name = "async-semaphore" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66d2be5973230861689460806b8db059bbd8bcb507cabaa71646ae89f5b2f2ee" +dependencies = [ + "event-listener", +] + [[package]] name = "async-stream" version = "0.2.1" @@ -121,15 +239,15 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "blocking" -version = "0.4.7" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2468ff7bf85066b4a3678fede6fe66db31846d753ff0adfbfab2c6a6e81612b" +checksum = "2640778f8053e72c11f621b0a5175a0560a269282aa98ed85107773ab8e2a556" dependencies = [ "async-channel", "atomic-waker", + "fastrand", "futures-lite", "once_cell", - "parking 1.0.6", "waker-fn", ] @@ -595,15 +713,15 @@ checksum = "de27142b013a8e869c14957e6d2edeef89e97c289e69d042ee3a49acd8b51789" [[package]] name = "futures-lite" -version = "0.1.11" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97999970129b808f0ccba93211201d431fcc12d7e1ffae03a61b5cedd1a7ced2" +checksum = "5b77e08e656f472d8ea84c472fa8b0a7a917883048e1cf2d4e34a323cd0aaf63" dependencies = [ "fastrand", "futures-core", "futures-io", "memchr", - "parking 2.0.0", + "parking", "pin-project-lite", "waker-fn", ] @@ -1111,6 +1229,16 @@ dependencies = [ "tempfile", ] +[[package]] +name = "nb-connect" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e847c76b390f44529c2071ef06d0b52fbb4bdb04cc8987a5cfa63954c000abca" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "net2" version = "0.2.35" @@ -1278,12 +1406,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "parking" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cb300f271742d4a2a66c01b6b2fa0c83dfebd2e0bf11addb879a3547b4ed87c" - [[package]] name = "parking" version = "2.0.0" @@ -1351,6 +1473,19 @@ version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" +[[package]] +name = "polling" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0307b8c7f438902536321f63c28cab0362f6ee89f1c7da47e3642ff956641c8b" +dependencies = [ + "cfg-if", + "libc", + "log", + "wepoll-sys-stjepang", + "winapi 0.3.9", +] + [[package]] name = "ppv-lite86" version = "0.2.9" @@ -1578,12 +1713,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "scoped-tls" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" - [[package]] name = "scopeguard" version = "1.1.0" @@ -1708,23 +1837,20 @@ dependencies = [ [[package]] name = "smol" -version = "0.1.18" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "620cbb3c6e34da57d3a248cda0cd01cd5848164dc062e764e65d06fe3ea7aed5" +checksum = "712d02afa6ac9e7b8c777fd181aff476d009280b54b8c28703d10fa5d7e80d83" dependencies = [ - "async-task", + "async-channel", + "async-executor", + "async-fs", + "async-io", + "async-lock", + "async-net", + "async-process", "blocking", - "concurrent-queue", - "fastrand", - "futures-io", - "futures-util", - "libc", + "futures-lite", "once_cell", - "scoped-tls", - "slab", - "socket2", - "wepoll-sys-stjepang", - "winapi 0.3.9", ] [[package]] @@ -1977,6 +2103,12 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" +[[package]] +name = "vec-arena" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" + [[package]] name = "version_check" version = "0.9.2" diff --git a/melib/Cargo.toml b/melib/Cargo.toml index 9ca54ff2b..2213a74aa 100644 --- a/melib/Cargo.toml +++ b/melib/Cargo.toml @@ -44,7 +44,7 @@ rusqlite = {version = "0.24.0", optional = true } libloading = "0.6.2" futures = "0.3.5" -smol = "0.1.18" +smol = "1.0.0" async-stream = "0.2.1" base64 = { version = "0.12.3", optional = true } flate2 = { version = "1.0.16", optional = true } diff --git a/melib/src/smtp.rs b/melib/src/smtp.rs index 3ad45dd2a..a0f32d087 100644 --- a/melib/src/smtp.rs +++ b/melib/src/smtp.rs @@ -50,7 +50,11 @@ * require_auth: true, * }, *}; - *std::thread::spawn(|| smol::run(futures::future::pending::<()>())); + * + *std::thread::Builder::new().spawn(move || { + * let ex = smol::Executor::new(); + * futures::executor::block_on(ex.run(futures::future::pending::<()>())); + *}).unwrap(); * *let mut conn = futures::executor::block_on(SmtpConnection::new_connection(conf)).unwrap(); *futures::executor::block_on(conn.mail_transaction(r#"To: l10@mail.gr @@ -73,7 +77,7 @@ use crate::error::{MeliError, Result, ResultIntoMeliError}; use futures::io::{AsyncReadExt, AsyncWriteExt}; use native_tls::TlsConnector; use smallvec::SmallVec; -use smol::blocking; +use smol::unblock; use smol::Async as AsyncWrapper; use std::borrow::Cow; use std::convert::TryFrom; @@ -310,7 +314,9 @@ impl SmtpConnection { let _path = path.clone(); socket.set_nonblocking(false)?; - let conn_result = blocking!(connector.connect(&_path, socket)); + let conn = unblock(move || connector.connect(&_path, socket)) + .await + .chain_err_kind(crate::error::ErrorKind::Network)?; /* if let Err(native_tls::HandshakeError::WouldBlock(midhandshake_stream)) = conn_result @@ -332,10 +338,8 @@ impl SmtpConnection { } } */ - AsyncWrapper::new(Connection::Tls( - conn_result.chain_err_kind(crate::error::ErrorKind::Network)?, - )) - .chain_err_kind(crate::error::ErrorKind::Network)? + AsyncWrapper::new(Connection::Tls(conn)) + .chain_err_kind(crate::error::ErrorKind::Network)? }; ret.write_all(b"EHLO meli.delivery\r\n") .await @@ -418,12 +422,15 @@ impl SmtpConnection { Password::CommandEval(command) => { let _command = command.clone(); - let mut output = blocking!(Command::new("sh") - .args(&["-c", &_command]) - .stdin(std::process::Stdio::piped()) - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::piped()) - .output())?; + let mut output = unblock(move || { + Command::new("sh") + .args(&["-c", &_command]) + .stdin(std::process::Stdio::piped()) + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) + .output() + }) + .await?; if !output.status.success() { return Err(MeliError::new(format!( "SMTP password evaluation command `{}` returned {}: {}", diff --git a/src/jobs.rs b/src/jobs.rs index c151b4e88..d82eff35e 100644 --- a/src/jobs.rs +++ b/src/jobs.rs @@ -132,7 +132,9 @@ impl JobExecutor { thread::Builder::new() .name("meli-reactor".to_string()) .spawn(move || { - smol::run(futures::future::pending::<()>()); + let ex = smol::Executor::new(); + + futures::executor::block_on(ex.run(futures::future::pending::<()>())); }) .unwrap(); @@ -223,7 +225,7 @@ impl JobExecutor { F: Future + Send + 'static, R: Send + 'static, { - self.spawn_specialized(smol::Task::blocking(async move { future.await })) + self.spawn_specialized(smol::unblock(move || futures::executor::block_on(future))) } } diff --git a/tools/src/imapshell.rs b/tools/src/imapshell.rs index 4a10a9dbf..e6df86b2a 100644 --- a/tools/src/imapshell.rs +++ b/tools/src/imapshell.rs @@ -48,7 +48,10 @@ fn main() -> Result<()> { BackendEventConsumer::new(std::sync::Arc::new(|_, _| ())), )?; - std::thread::spawn(|| smol::run(futures::future::pending::<()>())); + std::thread::spawn(move || { + let ex = smol::Executor::new(); + futures::executor::block_on(ex.run(futures::future::pending::<()>())); + }); (imap.as_any_mut()) .downcast_mut::() .unwrap() diff --git a/tools/src/mboxparse.rs b/tools/src/mboxparse.rs index 1abb8c564..0c861936c 100644 --- a/tools/src/mboxparse.rs +++ b/tools/src/mboxparse.rs @@ -21,7 +21,6 @@ extern crate melib; use melib::Result; -use melib::*; /// Parses e-mail from files and prints the debug information of the parsed `Envelope` /// diff --git a/tools/src/smtp_conn.rs b/tools/src/smtp_conn.rs index a8665f820..0d87dd0db 100644 --- a/tools/src/smtp_conn.rs +++ b/tools/src/smtp_conn.rs @@ -20,9 +20,10 @@ fn main() -> Result<()> { }, envelope_from: String::new(), }; - for _ in 0..1 { - std::thread::spawn(|| smol::run(futures::future::pending::<()>())); - } + std::thread::spawn(move || { + let ex = smol::Executor::new(); + futures::executor::block_on(ex.run(futures::future::pending::<()>())); + }); let mut conn = futures::executor::block_on(SmtpConnection::new_connection(conf)).unwrap(); futures::executor::block_on(conn.mail_transaction(