mail client (IMAP/SMTP)
git clone https://git.lucas.co/cce-mail.git
refactor(ipc): read requests with cce_ui::ipc::read_request_line
Byte-identical to the copy deleted here; it lives in cce-ui now (40c66d4).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
src/ipc.rs | 36 +-----------------------------------
1 file changed, 1 insertion(+), 35 deletions(-)
diff --git a/src/ipc.rs b/src/ipc.rs
index cf65943..514c0a4 100644
--- a/src/ipc.rs
+++ b/src/ipc.rs
@@ -114,7 +114,7 @@ pub fn spawn_listener(sender: calloop::channel::Sender<AppMessage>) {
std::thread::spawn(move || {
for conn in listener.incoming() {
let Ok(conn) = conn else { continue };
- let Some(line) = read_request_line(&conn, 64 * 1024, IO_TIMEOUT) else {
+ let Some(line) = cce_ui::ipc::read_request_line(&conn, 64 * 1024, IO_TIMEOUT) else {
continue;
};
let _ = conn.set_read_timeout(Some(IO_TIMEOUT));
@@ -622,37 +622,3 @@ mod tests {
}
}
}
-
-/// One request line from a control-socket client, bounded in size and in
-/// TOTAL time. Until 2026-10-02 this was `BufReader::read_line` on a socket
-/// with a per-read timeout only, so a client that connected and said nothing (or trickled a
-/// byte at a time) held the listener thread as long as it kept trickling. None on EOF before any byte, timeout,
-/// overflow or a read error.
-fn read_request_line(conn: &std::os::unix::net::UnixStream, limit: usize, deadline: std::time::Duration) -> Option<String> {
- use std::io::Read;
- let until = std::time::Instant::now() + deadline;
- let mut buf: Vec<u8> = Vec::new();
- let mut chunk = [0u8; 4096];
- let mut reader = conn;
- loop {
- let left = until.checked_duration_since(std::time::Instant::now()).filter(|d| !d.is_zero())?;
- conn.set_read_timeout(Some(left)).ok()?;
- let n = reader.read(&mut chunk).ok()?;
- if n == 0 {
- if buf.is_empty() {
- return None;
- }
- break;
- }
- buf.extend_from_slice(&chunk[..n]);
- if let Some(end) = buf.iter().position(|&b| b == b'\n') {
- buf.truncate(end + 1);
- break;
- }
- if buf.len() > limit {
- return None;
- }
- }
- let _ = conn.set_read_timeout(None);
- String::from_utf8(buf).ok()
-}