1use super::{socket_addr, SocketAddr};
2use crate::sys::unix::net::new_socket;
3
4use std::io;
5use std::os::unix::io::{AsRawFd, FromRawFd};
6use std::os::unix::net;
7use std::path::Path;
8
9pub(crate) fn connect(path: &Path) -> io::Result<net::UnixStream> {
10 let (sockaddr: sockaddr_un, socklen: u32) = socket_addr(path)?;
11 let sockaddr: *const sockaddr = &sockaddr as *const libc::sockaddr_un as *const libc::sockaddr;
12
13 let fd: i32 = new_socket(domain:libc::AF_UNIX, socket_type:libc::SOCK_STREAM)?;
14 let socket: UnixStream = unsafe { net::UnixStream::from_raw_fd(fd) };
15 match syscall!(connect(fd, sockaddr, socklen)) {
16 Ok(_) => {}
17 Err(ref err: &Error) if err.raw_os_error() == Some(libc::EINPROGRESS) => {}
18 Err(e: Error) => return Err(e),
19 }
20
21 Ok(socket)
22}
23
24pub(crate) fn pair() -> io::Result<(net::UnixStream, net::UnixStream)> {
25 super::pair(flags:libc::SOCK_STREAM)
26}
27
28pub(crate) fn local_addr(socket: &net::UnixStream) -> io::Result<SocketAddr> {
29 super::local_addr(socket:socket.as_raw_fd())
30}
31
32pub(crate) fn peer_addr(socket: &net::UnixStream) -> io::Result<SocketAddr> {
33 super::peer_addr(socket:socket.as_raw_fd())
34}
35