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:
+7
-30
@@ -1,38 +1,28 @@
|
||||
use std::net::TcpStream;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use anyhow::Result;
|
||||
use super::frame;
|
||||
|
||||
pub enum Connection {
|
||||
Tcp(TcpStream),
|
||||
Unix(UnixStream),
|
||||
pub struct Connection {
|
||||
inner: UnixStream,
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
pub fn connect_tcp(addr: &str) -> Result<Self> {
|
||||
let stream = TcpStream::connect(addr)?;
|
||||
stream.set_nodelay(true)?;
|
||||
Ok(Connection::Tcp(stream))
|
||||
pub fn from_stream(stream: UnixStream) -> Result<Self> {
|
||||
Ok(Connection { inner: stream })
|
||||
}
|
||||
|
||||
pub fn connect_unix(path: &str) -> Result<Self> {
|
||||
let stream = UnixStream::connect(path)?;
|
||||
Ok(Connection::Unix(stream))
|
||||
Ok(Connection { inner: stream })
|
||||
}
|
||||
|
||||
pub fn send<T: serde::Serialize>(&mut self, value: &T) -> Result<()> {
|
||||
let data = frame::serialize_frame(value)?;
|
||||
match self {
|
||||
Connection::Tcp(ref mut s) => frame::write_frame(s, &data),
|
||||
Connection::Unix(ref mut s) => frame::write_frame(s, &data),
|
||||
}
|
||||
frame::write_frame(&mut self.inner, &data)
|
||||
}
|
||||
|
||||
pub fn receive<T: serde::de::DeserializeOwned>(&mut self) -> Result<Option<T>> {
|
||||
let data = match self {
|
||||
Connection::Tcp(ref mut s) => frame::read_frame(s)?,
|
||||
Connection::Unix(ref mut s) => frame::read_frame(s)?,
|
||||
};
|
||||
let data = frame::read_frame(&mut self.inner)?;
|
||||
match data {
|
||||
Some(bytes) => {
|
||||
let value: T = frame::deserialize_frame(&bytes)?;
|
||||
@@ -41,17 +31,4 @@ impl Connection {
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn try_clone(&self) -> Result<Self> {
|
||||
match self {
|
||||
Connection::Tcp(s) => {
|
||||
let cloned = s.try_clone()?;
|
||||
Ok(Connection::Tcp(cloned))
|
||||
}
|
||||
Connection::Unix(s) => {
|
||||
let cloned = s.try_clone()?;
|
||||
Ok(Connection::Unix(cloned))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user