cleanup: notification socket creation

This commit is contained in:
Ashley Wulber 2023-07-07 16:50:22 -04:00 committed by Ashley Wulber
parent eabfa58bd5
commit cae8dc6a27

View file

@ -1,32 +1,21 @@
use color_eyre::eyre::Context;
use color_eyre::Result;
use std::os::fd::OwnedFd;
use tokio::net::UnixStream;
use std::os::unix::net::UnixStream;
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")?;
// Turn the other socket into a non-blocking fd, which we can pass to the child
// Turn the sockets into non-blocking fd, which we can pass to the child
// process
let fd_1 = {
let std_stream = sock_1
.into_std()
.wrap_err("failed to convert client socket to std socket")?;
std_stream
.set_nonblocking(false)
.wrap_err("failed to mark client socket as blocking")?;
OwnedFd::from(std_stream)
};
sock_1
.set_nonblocking(false)
.wrap_err("failed to mark client socket as blocking")?;
let fd_2 = {
let std_stream = sock_2
.into_std()
.wrap_err("failed to convert client socket to std socket")?;
std_stream
.set_nonblocking(false)
.wrap_err("failed to mark client socket as blocking")?;
OwnedFd::from(std_stream)
};
Ok((fd_1, fd_2))
sock_2
.set_nonblocking(false)
.wrap_err("failed to mark client socket as blocking")?;
Ok((OwnedFd::from(sock_1), OwnedFd::from(sock_2)))
}