mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
remove socket file after use
This commit is contained in:
@@ -2,9 +2,9 @@
|
|||||||
//! Delta Chat core RPC server.
|
//! Delta Chat core RPC server.
|
||||||
//!
|
//!
|
||||||
//! It speaks JSON Lines over stdio.
|
//! It speaks JSON Lines over stdio.
|
||||||
|
use std::env;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{env, ffi::OsStr};
|
|
||||||
|
|
||||||
use anyhow::{anyhow, Context as _, Result};
|
use anyhow::{anyhow, Context as _, Result};
|
||||||
use deltachat::constants::DC_VERSION_STR;
|
use deltachat::constants::DC_VERSION_STR;
|
||||||
@@ -14,6 +14,8 @@ use tokio::io::{self, AsyncBufReadExt, BufReader};
|
|||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
use yerpc::RpcServer as _;
|
use yerpc::RpcServer as _;
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
use std::ffi::OsString;
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
use tokio::net::UnixListener;
|
use tokio::net::UnixListener;
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
@@ -113,7 +115,7 @@ async fn main_impl() -> Result<()> {
|
|||||||
bail!("unix sockets are only supported on unix based operating systems");
|
bail!("unix sockets are only supported on unix based operating systems");
|
||||||
}
|
}
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
unix_socket_impl(&unix_socket_path, state, main_cancel.clone()).await?
|
unix_socket_impl(unix_socket_path, state, main_cancel.clone()).await?
|
||||||
} else {
|
} else {
|
||||||
stdio_impl(state, main_cancel.clone()).await?
|
stdio_impl(state, main_cancel.clone()).await?
|
||||||
};
|
};
|
||||||
@@ -193,7 +195,7 @@ async fn stdio_impl(
|
|||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
async fn unix_socket_impl(
|
async fn unix_socket_impl(
|
||||||
unix_socket_path: &OsStr,
|
unix_socket_path: OsString,
|
||||||
state: CommandApi,
|
state: CommandApi,
|
||||||
main_cancel: CancellationToken,
|
main_cancel: CancellationToken,
|
||||||
) -> Result<(
|
) -> Result<(
|
||||||
@@ -202,7 +204,7 @@ async fn unix_socket_impl(
|
|||||||
)> {
|
)> {
|
||||||
let cancel = main_cancel.clone();
|
let cancel = main_cancel.clone();
|
||||||
|
|
||||||
let listener = UnixListener::bind(unix_socket_path)?;
|
let listener = UnixListener::bind(&unix_socket_path)?;
|
||||||
|
|
||||||
let recv_task: JoinHandle<anyhow::Result<()>> = tokio::spawn(async move {
|
let recv_task: JoinHandle<anyhow::Result<()>> = tokio::spawn(async move {
|
||||||
let _cancel_guard = cancel.clone().drop_guard();
|
let _cancel_guard = cancel.clone().drop_guard();
|
||||||
@@ -241,7 +243,7 @@ async fn unix_socket_impl(
|
|||||||
read_lines.next_line()
|
read_lines.next_line()
|
||||||
=> match message? {
|
=> match message? {
|
||||||
None => {
|
None => {
|
||||||
log::info!("EOF reached on stdin");
|
log::info!("unix socket closed {addr:?}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Some(message) => message,
|
Some(message) => message,
|
||||||
@@ -274,15 +276,15 @@ async fn unix_socket_impl(
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
// todo handle shutdown of _send_task and _receive_task
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::info!("connection failed {e:#}");
|
log::info!("connection failed {e:#}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// todo shutdown all remaining unix streams via their shutdown method
|
|
||||||
|
drop(listener);
|
||||||
|
std::fs::remove_file(unix_socket_path)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user