src/server/command_socket.rs: correctly handle/spawn handle parallel connections

This commit is contained in:
Dietmar Maurer 2019-04-10 11:05:00 +02:00
parent 9b002cbc5f
commit cfb2d3c17c
1 changed files with 27 additions and 23 deletions

View File

@ -18,7 +18,6 @@ pub fn create_control_socket<P, F>(path: P, f: F) -> Result<impl Future<Item=(),
F: Send + Sync +'static + Fn(Value) -> Result<Value, Error>, F: Send + Sync +'static + Fn(Value) -> Result<Value, Error>,
{ {
let path: PathBuf = path.into(); let path: PathBuf = path.into();
let path1: PathBuf = path.clone();
let socket = UnixListener::bind(&path)?; let socket = UnixListener::bind(&path)?;
@ -35,6 +34,9 @@ pub fn create_control_socket<P, F>(path: P, f: F) -> Result<impl Future<Item=(),
let path = path3.clone(); let path = path3.clone();
let path2 = path3.clone(); let path2 = path3.clone();
let abort_future = super::last_worker_future().map_err(|_| {});
tokio::spawn(
tokio::io::lines(std::io::BufReader::new(rx)) tokio::io::lines(std::io::BufReader::new(rx))
.map_err(move |err| { eprintln!("control socket {:?} read error: {}", path, err); }) .map_err(move |err| { eprintln!("control socket {:?} read error: {}", path, err); })
.and_then(move |cmd| { .and_then(move |cmd| {
@ -57,7 +59,9 @@ pub fn create_control_socket<P, F>(path: P, f: F) -> Result<impl Future<Item=(),
tx.write_all(resp.as_bytes()) tx.write_all(resp.as_bytes())
.map_err(|err| { eprintln!("control socket {:?} write response error: {}", path2, err); }) .map_err(|err| { eprintln!("control socket {:?} write response error: {}", path2, err); })
}) })
.select(abort_future)
.then(move |_| { Ok(()) })
)
}); });
let abort_future = super::last_worker_future().map_err(|_| {}); let abort_future = super::last_worker_future().map_err(|_| {});