79615715

Date: 2025-05-10 17:02:09
Score: 0.5
Natty:
Report link

nginx expects a datagram socket, not a stream socket. you can create a datagram socket like this:

use std::os::unix::net::UnixDatagram;

fn main() -> std::io::Result<()> {
    let socket_path = format!(
        "{}/logtool.sock",
        std::env::var("XDG_RUNTIME_DIR").unwrap_or("/tmp".to_string())
    );
    let _ = std::fs::remove_file(&socket_path);
    let listener = UnixDatagram::bind(socket_path)?;

    loop {
        let mut buf = vec![0; 1_024];
        let read = listener.recv(&mut buf)?;
        let buf = &buf[..read];
        dbg!(buf);
    }
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: tauon