Skip to content

Using accept on macOS unix socket always raise EINVAL #631

@youknowone

Description

@youknowone

accept_raw is fine.

This happens because SO_NOSIGPIPE is set for accept.

If this is not a bug, I'd like to know if this is a design decision. Then adding a note on macOS line "use accept_raw for unix socket" will be helpful.

use socket2::{Domain, Socket, Type, SockAddr};
use std::thread;

fn main() {
    let path = "/tmp/test.sock";
    let _ = std::fs::remove_file(path);

    let server = Socket::new(Domain::UNIX, Type::STREAM, None).unwrap();
    server.bind(&SockAddr::unix(path).unwrap()).unwrap();
    server.listen(1).unwrap();

    thread::spawn(move || {
        Socket::new(Domain::UNIX, Type::STREAM, None)
            .unwrap()
            .connect(&SockAddr::unix(path).unwrap())
            .unwrap();
    });

    server.accept().expect("macOS always fail here");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions