Refactor IPC and DTO structures; remove unused code and streamline message handling
- Removed unused structs and methods from `response.rs`, `usage.rs`, and `client.rs`. - Simplified `Connection` handling in `conn.rs` to only support Unix sockets. - Updated `IpcServer` to exclusively use Unix sockets and removed TCP handling. - Cleaned up `editlog.rs` by removing loading and recent entry methods. - Refactored `memory.rs` to eliminate unused functions related to lesson promotion and retrospective creation. - Enhanced `search.rs` to support multiple search providers and improved error handling. - Updated chat view logic to simplify message display and improve user experience. - Removed deprecated modules and constants from various files to streamline the codebase.
This commit is contained in:
+4
-68
@@ -1,84 +1,20 @@
|
||||
use std::net::TcpListener;
|
||||
use std::os::unix::net::UnixListener;
|
||||
use std::thread;
|
||||
use anyhow::Result;
|
||||
use super::conn::Connection;
|
||||
|
||||
enum ListenerKind {
|
||||
Tcp(TcpListener),
|
||||
Unix(UnixListener),
|
||||
}
|
||||
|
||||
pub struct IpcServer {
|
||||
listener: ListenerKind,
|
||||
listener: UnixListener,
|
||||
}
|
||||
|
||||
impl IpcServer {
|
||||
pub fn bind(addr: &str) -> Result<Self> {
|
||||
let listener = TcpListener::bind(addr)?;
|
||||
Ok(IpcServer { listener: ListenerKind::Tcp(listener) })
|
||||
}
|
||||
|
||||
pub fn bind_unix(path: &str) -> Result<Self> {
|
||||
let _ = std::fs::remove_file(path);
|
||||
let listener = UnixListener::bind(path)?;
|
||||
Ok(IpcServer { listener: ListenerKind::Unix(listener) })
|
||||
Ok(IpcServer { listener })
|
||||
}
|
||||
|
||||
pub fn accept(&self) -> Result<Connection> {
|
||||
match &self.listener {
|
||||
ListenerKind::Tcp(l) => {
|
||||
let (stream, _addr) = l.accept()?;
|
||||
stream.set_nodelay(true)?;
|
||||
Ok(Connection::Tcp(stream))
|
||||
}
|
||||
ListenerKind::Unix(l) => {
|
||||
let (stream, _addr) = l.accept()?;
|
||||
Ok(Connection::Unix(stream))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn accept_with_handler<F>(self, handler: F) -> thread::JoinHandle<()>
|
||||
where
|
||||
F: Fn(Connection) -> Result<()> + Send + 'static,
|
||||
{
|
||||
match self.listener {
|
||||
ListenerKind::Tcp(l) => {
|
||||
thread::spawn(move || {
|
||||
for stream in l.incoming() {
|
||||
match stream {
|
||||
Ok(s) => {
|
||||
let _ = s.set_nodelay(true);
|
||||
if let Err(e) = handler(Connection::Tcp(s)) {
|
||||
eprintln!("ipc handler error: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("ipc accept error: {}", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
ListenerKind::Unix(l) => {
|
||||
thread::spawn(move || {
|
||||
for stream in l.incoming() {
|
||||
match stream {
|
||||
Ok(s) => {
|
||||
if let Err(e) = handler(Connection::Unix(s)) {
|
||||
eprintln!("ipc handler error: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("ipc accept error: {}", e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
let (stream, _addr) = self.listener.accept()?;
|
||||
Connection::from_stream(stream)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user