2023-06-27 15:26:52 -04:00
|
|
|
use color_eyre::eyre::Context;
|
|
|
|
|
use color_eyre::Result;
|
|
|
|
|
use std::os::fd::OwnedFd;
|
2023-07-07 16:50:22 -04:00
|
|
|
use std::os::unix::net::UnixStream;
|
2023-06-27 15:26:52 -04:00
|
|
|
|
|
|
|
|
pub fn create_socket() -> Result<(OwnedFd, OwnedFd)> {
|
|
|
|
|
// Create a new pair of unnamed Unix sockets
|
|
|
|
|
let (sock_1, sock_2) = UnixStream::pair().wrap_err("failed to create socket pair")?;
|
|
|
|
|
|
2023-07-07 16:50:22 -04:00
|
|
|
// Turn the sockets into non-blocking fd, which we can pass to the child
|
2023-06-27 15:26:52 -04:00
|
|
|
// process
|
2023-07-07 16:50:22 -04:00
|
|
|
sock_1
|
|
|
|
|
.set_nonblocking(false)
|
|
|
|
|
.wrap_err("failed to mark client socket as blocking")?;
|
2023-06-27 15:26:52 -04:00
|
|
|
|
2023-07-07 16:50:22 -04:00
|
|
|
sock_2
|
|
|
|
|
.set_nonblocking(false)
|
|
|
|
|
.wrap_err("failed to mark client socket as blocking")?;
|
|
|
|
|
|
|
|
|
|
Ok((OwnedFd::from(sock_1), OwnedFd::from(sock_2)))
|
2023-06-27 15:26:52 -04:00
|
|
|
}
|