pub fn new(timeout: Duration) -> Result<Self> {
        // If this Parsec instance was socket activated (see the `parsec.socket`
        // file), the listener will be opened by systemd and passed to the
        // process.
        // If Parsec was service activated or not started under systemd, this
        // will return `0`.
        let listener = match sd_notify::listen_fds()? {
            0 => {
                let socket = Path::new(SOCKET_PATH);

                if socket.exists() {
                    fs::remove_file(&socket)?;
                }

                let listener = UnixListener::bind(SOCKET_PATH)?;
                listener.set_nonblocking(true)?;

                listener
            }
            1 => {
                // No need to set the socket as non-blocking, parsec.service
                // already requests that.
                let nfd = sd_notify::SD_LISTEN_FDS_START;
                // Safe as listen_fds gives us the information that one file descriptor was
                // received and its value starts from SD_LISTEN_FDS_START.
                unsafe { UnixListener::from_raw_fd(nfd) }
            }
            n => {
                error!(
                    "Received too many file descriptors ({} received, 0 or 1 expected).",
                    n
                );
                return Err(Error::new(
                    ErrorKind::InvalidData,
                    "too many file descriptors received",
                ));
            }
        };

        Ok(Self { listener, timeout })
    }
/// Initialise the connection to the Unix socket.
///
/// # Panics
/// - if a file/socket exists at the path specified for the socket and `remove_file`
/// fails
/// - if binding to the socket path fails
Initialise the connection to the Unix socket.
Initialise the connection to the Unix socket .
pub fn new(timeout: Duration) -> Result<Self> {
        // If this Parsec instance was socket activated (see the `parsec.socket`
        // file), the listener will be opened by systemd and passed to the
        // process.
        // If Parsec was service activated or not started under systemd, this
        // will return `0`.
        let listener = match sd_notify::listen_fds()? {
            0 => {
                let socket = Path::new(SOCKET_PATH);
                if socket.exists() {
                    fs::remove_file(&socket)?;
                }
                let listener = UnixListener::bind(SOCKET_PATH)?;
                listener.set_nonblocking(true)?;
                listener
            }
            1 => {
                // No need to set the socket as non-blocking, parsec.service
                // already requests that.
                let nfd = sd_notify::SD_LISTEN_FDS_START;
                // Safe as listen_fds gives us the information that one file descriptor was
                // received and its value starts from SD_LISTEN_FDS_START.
                unsafe { UnixListener::from_raw_fd(nfd) }
            }
            n => {
                error!(
                    "Received too many file descriptors ({} received, 0 or 1 expected).",
                    n
                );
                return Err(Error::new(
                    ErrorKind::InvalidData,
                    "too many file descriptors received",
                ));
            }
        };
        Ok(Self { listener, timeout })
    }
pub fn new ( timeout : Duration ) -> Result < Self > { // If this Parsec instance was socket activated (see the `parsec.socket` // file), the listener will be opened by systemd and passed to the // process. // If Parsec was service activated or not started under systemd, this // will return `0`. let listener = match sd_notify :: listen_fds ( ) ? { 0 => { let socket = Path :: new ( SOCKET_PATH ) ; if socket . exists ( ) { fs :: remove_file ( & socket ) ? ; } let listener = UnixListener :: bind ( SOCKET_PATH ) ? ; listener . set_nonblocking ( true ) ? ; listener } 1 => { // No need to set the socket as non-blocking, parsec.service // already requests that. let nfd = sd_notify :: SD_LISTEN_FDS_START ; // Safe as listen_fds gives us the information that one file descriptor was // received and its value starts from SD_LISTEN_FDS_START. unsafe { UnixListener :: from_raw_fd ( nfd ) } } n => { error ! ( " " n ) ; return Err ( Error :: new ( ErrorKind :: InvalidData , " " , ) ) ; } } ; Ok ( Self { listener , timeout } ) }
Initialise the connection to the Unix socket.
Initialise the connection to the Unix socket .
timeout
Duration
timeout
Duration
panics
if a file/socket exists at the path specified for the socket and `remove_file`
fails
if binding to the socket path fails
if a file / socket exists at the path specified for the socket and ` remove_file ` fails if binding to the socket path fails