cleanup: notification socket creation
This commit is contained in:
parent
eabfa58bd5
commit
cae8dc6a27
1 changed files with 10 additions and 21 deletions
|
|
@ -1,32 +1,21 @@
|
||||||
use color_eyre::eyre::Context;
|
use color_eyre::eyre::Context;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use std::os::fd::OwnedFd;
|
use std::os::fd::OwnedFd;
|
||||||
use tokio::net::UnixStream;
|
use std::os::unix::net::UnixStream;
|
||||||
|
|
||||||
pub fn create_socket() -> Result<(OwnedFd, OwnedFd)> {
|
pub fn create_socket() -> Result<(OwnedFd, OwnedFd)> {
|
||||||
// Create a new pair of unnamed Unix sockets
|
// Create a new pair of unnamed Unix sockets
|
||||||
let (sock_1, sock_2) = UnixStream::pair().wrap_err("failed to create socket pair")?;
|
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
|
// process
|
||||||
let fd_1 = {
|
sock_1
|
||||||
let std_stream = sock_1
|
.set_nonblocking(false)
|
||||||
.into_std()
|
.wrap_err("failed to mark client socket as blocking")?;
|
||||||
.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)
|
|
||||||
};
|
|
||||||
|
|
||||||
let fd_2 = {
|
sock_2
|
||||||
let std_stream = sock_2
|
.set_nonblocking(false)
|
||||||
.into_std()
|
.wrap_err("failed to mark client socket as blocking")?;
|
||||||
.wrap_err("failed to convert client socket to std socket")?;
|
|
||||||
std_stream
|
Ok((OwnedFd::from(sock_1), OwnedFd::from(sock_2)))
|
||||||
.set_nonblocking(false)
|
|
||||||
.wrap_err("failed to mark client socket as blocking")?;
|
|
||||||
OwnedFd::from(std_stream)
|
|
||||||
};
|
|
||||||
Ok((fd_1, fd_2))
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue