Pin future on stack

This commit is contained in:
zonyitoo
2020-03-02 22:08:01 +08:00
parent 95601de02f
commit ee92e6414b
7 changed files with 45 additions and 14 deletions
+7 -2
View File
@@ -10,7 +10,7 @@ use futures::{
FutureExt,
};
use log::{error, info};
use tokio::runtime::Builder;
use tokio::{self, runtime::Builder};
use shadowsocks::{
acl::AccessControl,
@@ -278,7 +278,12 @@ fn main() {
let rt_handle = runtime.handle().clone();
runtime.block_on(async move {
let abort_signal = monitor::create_signal_monitor();
match future::select(run_local(config, rt_handle).boxed(), abort_signal.boxed()).await {
let server = run_local(config, rt_handle);
tokio::pin!(abort_signal);
tokio::pin!(server);
match future::select(server, abort_signal).await {
// Server future resolved without an error. This should never happen.
Either::Left((Ok(..), ..)) => panic!("server exited unexpectly"),
// Server future resolved with error, which are listener errors in most cases
+7 -2
View File
@@ -15,7 +15,7 @@ use futures::{
FutureExt,
};
use log::{error, info};
use tokio::runtime::Builder;
use tokio::{self, runtime::Builder};
use shadowsocks::{
acl::AccessControl,
@@ -191,7 +191,12 @@ fn main() {
runtime.block_on(async move {
let abort_signal = monitor::create_signal_monitor();
match future::select(run_manager(config, rt_handle).boxed(), abort_signal.boxed()).await {
let server = run_manager(config, rt_handle);
tokio::pin!(abort_signal);
tokio::pin!(server);
match future::select(server, abort_signal).await {
// Server future resolved without an error. This should never happen.
Either::Left((Ok(..), ..)) => panic!("server exited unexpectly"),
// Server future resolved with error, which are listener errors in most cases
+7 -2
View File
@@ -10,7 +10,7 @@ use futures::{
FutureExt,
};
use log::{error, info};
use tokio::runtime::Builder;
use tokio::{self, runtime::Builder};
use shadowsocks::{
acl::AccessControl,
@@ -251,7 +251,12 @@ fn main() {
runtime.block_on(async move {
let abort_signal = monitor::create_signal_monitor();
match future::select(run_local(config, rt_handle).boxed(), abort_signal.boxed()).await {
let server = run_local(config, rt_handle);
tokio::pin!(abort_signal);
tokio::pin!(server);
match future::select(server, abort_signal).await {
// Server future resolved without an error. This should never happen.
Either::Left((Ok(..), ..)) => panic!("server exited unexpectly"),
// Server future resolved with error, which are listener errors in most cases
+7 -2
View File
@@ -15,7 +15,7 @@ use futures::{
FutureExt,
};
use log::{error, info};
use tokio::runtime::Builder;
use tokio::{self, runtime::Builder};
use shadowsocks::{
acl::AccessControl,
@@ -243,7 +243,12 @@ fn main() {
runtime.block_on(async move {
let abort_signal = monitor::create_signal_monitor();
match future::select(run_server(config, rt_handle).boxed(), abort_signal.boxed()).await {
let server = run_server(config, rt_handle);
tokio::pin!(abort_signal);
tokio::pin!(server);
match future::select(server, abort_signal).await {
// Server future resolved without an error. This should never happen.
Either::Left((Ok(..), ..)) => panic!("server exited unexpectly"),
// Server future resolved with error, which are listener errors in most cases
+7 -2
View File
@@ -10,7 +10,7 @@ use futures::{
FutureExt,
};
use log::{error, info};
use tokio::runtime::Builder;
use tokio::{self, runtime::Builder};
use shadowsocks::{
crypto::CipherType,
@@ -247,7 +247,12 @@ fn main() {
runtime.block_on(async move {
let abort_signal = monitor::create_signal_monitor();
match future::select(run_local(config, rt_handle).boxed(), abort_signal.boxed()).await {
let server = run_local(config, rt_handle);
tokio::pin!(abort_signal);
tokio::pin!(server);
match future::select(server, abort_signal).await {
// Server future resolved without an error. This should never happen.
Either::Left((Ok(..), ..)) => panic!("server exited unexpectly"),
// Server future resolved with error, which are listener errors in most cases
+5 -2
View File
@@ -12,7 +12,7 @@ use std::{
};
use byte_string::ByteStr;
use futures::{future, FutureExt};
use futures::future;
use log::{debug, error, trace, warn};
#[cfg(unix)]
use tokio::net::UnixDatagram;
@@ -85,7 +85,10 @@ impl ServerInstance {
tokio::spawn(async move {
let server = server::run_with(config, flow_stat, server_state);
let _ = future::select(server.boxed(), watcher_rx.boxed()).await;
tokio::pin!(server);
tokio::pin!(watcher_rx);
let _ = future::select(server, watcher_rx).await;
debug!("server listening on port {} exited", server_port);
});
}
+5 -2
View File
@@ -8,7 +8,7 @@ use std::{
};
use bytes::BytesMut;
use futures::{self, future, stream::FuturesUnordered, FutureExt, StreamExt};
use futures::{self, future, stream::FuturesUnordered, StreamExt};
use log::{debug, error, info, trace, warn};
use lru_time_cache::{Entry, LruCache};
use tokio::{
@@ -128,7 +128,10 @@ impl UdpAssociation {
};
// Resolved only if watcher_rx resolved
let _ = future::select(transfer_fut.boxed(), watcher_rx.boxed()).await;
tokio::pin!(transfer_fut);
tokio::pin!(watcher_rx);
let _ = future::select(transfer_fut, watcher_rx).await;
debug!("UDP ASSOCIATE {} <- .. finished", src_addr);
});