executor work
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use crate::tools::*;
|
||||
use crate::veilid_client_capnp::*;
|
||||
use async_std::net::TcpListener;
|
||||
use async_std::prelude::FutureExt;
|
||||
use capnp::capability::Promise;
|
||||
use capnp_rpc::{pry, rpc_twoparty_capnp, twoparty, RpcSystem};
|
||||
use failure::*;
|
||||
@@ -232,7 +231,7 @@ impl veilid_server::Server for VeilidServerImpl {
|
||||
// --- Client API Server-Side ---------------------------------
|
||||
|
||||
type ClientApiAllFuturesJoinHandle =
|
||||
async_std::task::JoinHandle<Result<Vec<()>, Box<(dyn std::error::Error + 'static)>>>;
|
||||
JoinHandle<Result<Vec<()>, Box<(dyn std::error::Error + 'static)>>>;
|
||||
|
||||
struct ClientApiInner {
|
||||
veilid_api: veilid_core::VeilidAPI,
|
||||
@@ -286,13 +285,15 @@ impl ClientApi {
|
||||
let listener = TcpListener::bind(bind_addr).await?;
|
||||
debug!("Client API listening on: {:?}", bind_addr);
|
||||
|
||||
// Get the
|
||||
// Process the incoming accept stream
|
||||
// xxx switch to stoptoken and use stream wrapper for tokio
|
||||
let mut incoming = listener.incoming();
|
||||
let stop = self.inner.borrow().stop.clone();
|
||||
let incoming_loop = async move {
|
||||
while let Some(stream_result) = stop.instance_none().race(incoming.next()).await {
|
||||
let stream = stream_result?;
|
||||
stream.set_nodelay(true)?;
|
||||
// xxx use tokio split code too
|
||||
let (reader, writer) = stream.split();
|
||||
let network = twoparty::VatNetwork::new(
|
||||
reader,
|
||||
@@ -303,7 +304,7 @@ impl ClientApi {
|
||||
|
||||
let rpc_system = RpcSystem::new(Box::new(network), Some(client.clone().client));
|
||||
|
||||
async_std::task::spawn_local(rpc_system.map(drop));
|
||||
spawn_local(rpc_system.map(drop));
|
||||
}
|
||||
Ok::<(), Box<dyn std::error::Error>>(())
|
||||
};
|
||||
@@ -332,7 +333,7 @@ impl ClientApi {
|
||||
|
||||
if let Some(request_promise) = request(id, registration) {
|
||||
let registration_map2 = registration_map1.clone();
|
||||
async_std::task::spawn_local(request_promise.promise.map(move |r| match r {
|
||||
spawn_local(request_promise.promise.map(move |r| match r {
|
||||
Ok(_) => {
|
||||
if let Some(ref mut s) =
|
||||
registration_map2.borrow_mut().registrations.get_mut(&id)
|
||||
@@ -385,6 +386,6 @@ impl ClientApi {
|
||||
.iter()
|
||||
.map(|addr| self.clone().handle_incoming(*addr, client.clone()));
|
||||
let bind_futures_join = futures::future::try_join_all(bind_futures);
|
||||
self.inner.borrow_mut().join_handle = Some(async_std::task::spawn_local(bind_futures_join));
|
||||
self.inner.borrow_mut().join_handle = Some(spawn_local(bind_futures_join));
|
||||
}
|
||||
}
|
||||
|
@@ -6,15 +6,16 @@ mod client_api;
|
||||
mod cmdline;
|
||||
mod server;
|
||||
mod settings;
|
||||
mod tools;
|
||||
#[cfg(unix)]
|
||||
mod unix;
|
||||
mod veilid_logs;
|
||||
#[cfg(windows)]
|
||||
mod windows;
|
||||
|
||||
use async_std::task;
|
||||
use cfg_if::*;
|
||||
use server::*;
|
||||
use tools::*;
|
||||
use tracing::*;
|
||||
use veilid_logs::*;
|
||||
|
||||
@@ -59,7 +60,7 @@ fn main() -> Result<(), String> {
|
||||
// Handle non-normal server modes
|
||||
if !matches!(server_mode, ServerMode::Normal) {
|
||||
// run the server to set the node id and quit
|
||||
return task::block_on(async {
|
||||
return block_on(async {
|
||||
// Init combined console/file logger
|
||||
let _logs = VeilidLogs::setup(settings.clone())?;
|
||||
|
||||
@@ -93,7 +94,7 @@ fn main() -> Result<(), String> {
|
||||
.expect("Error setting Ctrl-C handler");
|
||||
|
||||
// Run the server loop
|
||||
task::block_on(async {
|
||||
block_on(async {
|
||||
// Init combined console/file logger
|
||||
let _logs = VeilidLogs::setup(settings.clone())?;
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
use crate::client_api;
|
||||
use crate::settings::*;
|
||||
use crate::tools::*;
|
||||
use flume::{unbounded, Receiver, Sender};
|
||||
use lazy_static::*;
|
||||
use parking_lot::Mutex;
|
||||
@@ -77,7 +78,7 @@ pub async fn run_veilid_server_internal(
|
||||
|
||||
// Process all updates
|
||||
let capi2 = capi.clone();
|
||||
let update_receiver_jh = async_std::task::spawn_local(async move {
|
||||
let update_receiver_jh = spawn_local(async move {
|
||||
while let Ok(change) = receiver.recv_async().await {
|
||||
if let Some(capi) = &capi2 {
|
||||
// Handle state changes on main thread for capnproto rpc
|
||||
@@ -115,7 +116,7 @@ pub async fn run_veilid_server_internal(
|
||||
break;
|
||||
}
|
||||
}
|
||||
async_std::task::sleep(Duration::from_millis(100)).await;
|
||||
sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
match veilid_api.debug("txtrecord".to_string()).await {
|
||||
Ok(v) => {
|
||||
|
48
veilid-server/src/tools.rs
Normal file
48
veilid-server/src/tools.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use cfg_if::*;
|
||||
use core::future::Future;
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(feature="rt-async-std")] {
|
||||
pub use async_std::task::JoinHandle;
|
||||
pub use async_std::net::TcpListener;
|
||||
//pub use async_std::net::TcpStream;
|
||||
//pub use async_std::future::TimeoutError;
|
||||
pub fn spawn<F: Future<Output = T> + Send + 'static, T: Send + 'static>(f: F) -> JoinHandle<T> {
|
||||
async_std::task::spawn_local(f)
|
||||
}
|
||||
pub fn spawn_local<F: Future<Output = T> + 'static, T: 'static>(f: F) -> JoinHandle<T> {
|
||||
async_std::task::spawn_local(f)
|
||||
}
|
||||
pub fn spawn_detached_local<F: Future<Output = T> + 'static, T: 'static>(f: F) {
|
||||
let _ = async_std::task::spawn_local(f);
|
||||
}
|
||||
pub use async_std::task::sleep;
|
||||
pub use async_std::future::timeout;
|
||||
pub fn block_on<F: Future<Output = T>, T>(f: F) -> T {
|
||||
async_std::task::block_on(f)
|
||||
}
|
||||
} else if #[cfg(feature="rt-tokio")] {
|
||||
pub use tokio::task::JoinHandle;
|
||||
pub use tokio::net::TcpListener;
|
||||
//pub use tokio::net::TcpStream;
|
||||
//pub use tokio_util::compat::*;
|
||||
pub use tokio::time::error::Elapsed as TimeoutError;
|
||||
pub fn spawn<F: Future<Output = T> + Send + 'static, T: Send + 'static>(f: F) -> JoinHandle<T> {
|
||||
tokio::task::spawn(f)
|
||||
}
|
||||
pub fn spawn_local<F: Future<Output = T> + 'static, T: 'static>(f: F) -> JoinHandle<T> {
|
||||
tokio::task::spawn_local(f)
|
||||
}
|
||||
pub fn spawn_detached_local<F: Future<Output = T> + 'static, T: 'static>(f: F) {
|
||||
let _ = tokio::task::spawn_local(f);
|
||||
}
|
||||
pub use tokio::time::sleep;
|
||||
pub use tokio::time::timeout;
|
||||
pub fn block_on<F: Future<Output = T>, T>(f: F) -> T {
|
||||
let rt = tokio::runtime::Runtime::new().unwrap();
|
||||
let local = tokio::task::LocalSet::new();
|
||||
local.block_on(&rt, f)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
use crate::server::*;
|
||||
use crate::settings::Settings;
|
||||
use crate::tools::*;
|
||||
use crate::veilid_logs::*;
|
||||
use async_std::stream::StreamExt;
|
||||
use async_std::task;
|
||||
use clap::ArgMatches;
|
||||
use futures::StreamExt;
|
||||
use signal_hook::consts::signal::*;
|
||||
use signal_hook_async_std::Signals;
|
||||
use std::io::Read;
|
||||
@@ -96,7 +96,7 @@ pub fn run_daemon(settings: Settings, _matches: ArgMatches) -> Result<(), String
|
||||
};
|
||||
|
||||
// Now, run the server
|
||||
task::block_on(async {
|
||||
block_on(async {
|
||||
// Init combined console/file logger
|
||||
let _logs = VeilidLogs::setup(settings.clone())?;
|
||||
|
||||
@@ -110,7 +110,7 @@ pub fn run_daemon(settings: Settings, _matches: ArgMatches) -> Result<(), String
|
||||
.map_err(|e| format!("failed to init signals: {}", e))?;
|
||||
let handle = signals.handle();
|
||||
|
||||
let signals_task = async_std::task::spawn(handle_signals(signals));
|
||||
let signals_task = spawn(handle_signals(signals));
|
||||
|
||||
let res = run_veilid_server(settings, ServerMode::Normal).await;
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
use crate::settings::*;
|
||||
use crate::tools::*;
|
||||
use clap::ArgMatches;
|
||||
use log::*;
|
||||
use std::ffi::OsString;
|
||||
|
Reference in New Issue
Block a user