use std::{
io,
net::{TcpListener, UdpSocket},
os::unix::io::FromRawFd,
};
use log::debug;
use crate::sys::get_launch_activate_socket;
pub fn get_launch_activate_tcp_listener(name: &str, nonblock: bool) -> io::Result<TcpListener> {
let fd = get_launch_activate_socket(name)?;
debug!("created TCP listener from launch activate socket {}", fd);
let listener = unsafe { TcpListener::from_raw_fd(fd) };
if nonblock {
listener.set_nonblocking(true)?;
}
Ok(listener)
}
pub fn get_launch_activate_udp_socket(name: &str, nonblock: bool) -> io::Result<UdpSocket> {
let fd = get_launch_activate_socket(name)?;
debug!("created UDP socket from launch activate socket {}", fd);
let socket = unsafe { UdpSocket::from_raw_fd(fd) };
if nonblock {
socket.set_nonblocking(true)?;
}
Ok(socket)
}