// Sets up the server side socket with the node IP:port
Sets up the server side socket with the node IP:port
Sets up the server side socket with the node IP : port
fn init_listener(&self, local_addr: &SocketAddr) -> Result<TcpListener, TransportErrorCode> {
        let socket = if local_addr.is_ipv6() {
            TcpSocket::new_v6()
        } else {
            TcpSocket::new_v4()
        };
        let socket = match socket {
            Ok(socket) => socket,
            Err(e) => {
                warn!(
                    every_n_seconds => 30,
                    self.log,
                    "ControlPlane::listen(): Failed to create socket: local_addr = {:?} {:?}",
                    local_addr,
                    e
                );
                return Err(TransportErrorCode::ServerSocketCreateFailed);
            }
        };
        // TODO: set reuse flags only for tests if needed
        if socket.set_reuseaddr(true).is_err() {
            return Err(TransportErrorCode::ServerSocketAddrReuseFailed);
        }
        if socket.set_reuseport(true).is_err() {
            return Err(TransportErrorCode::ServerSocketPortReuseFailed);
        }
        if let Err(e) = socket.bind(*local_addr) {
            warn!(
                every_n_seconds => 30,
                self.log,
                "ControlPlane::listen(): Failed to bind: local_addr = {:?} {:?}", local_addr, e
            );
            return Err(TransportErrorCode::ServerSocketBindFailed);
        }
        match socket.listen(128) {
            Ok(listener) => Ok(listener),
            Err(e) => {
                warn!(
                    self.log,
                    "ControlPlane::listen(): Failed to listen: local_addr = {:?} {:?}",
                    local_addr,
                    e
                );
                Err(TransportErrorCode::ServerSocketListenFailed)
            }
        }
    }
fn init_listener ( & self , local_addr : & SocketAddr ) -> Result < TcpListener , TransportErrorCode > { let socket = if local_addr . is_ipv6 ( ) { TcpSocket :: new_v6 ( ) } else { TcpSocket :: new_v4 ( ) } ; let socket = match socket { Ok ( socket ) => socket , Err ( e ) => { warn ! ( every_n_seconds 30 self log " " local_addr e ) ; return Err ( TransportErrorCode :: ServerSocketCreateFailed ) ; } } ; // TODO: set reuse flags only for tests if needed if socket . set_reuseaddr ( true ) . is_err ( ) { return Err ( TransportErrorCode :: ServerSocketAddrReuseFailed ) ; } if socket . set_reuseport ( true ) . is_err ( ) { return Err ( TransportErrorCode :: ServerSocketPortReuseFailed ) ; } if let Err ( e ) = socket . bind ( * local_addr ) { warn ! ( every_n_seconds 30 self log " " local_addr e ) ; return Err ( TransportErrorCode :: ServerSocketBindFailed ) ; } match socket . listen ( 128 ) { Ok ( listener ) => Ok ( listener ) , Err ( e ) => { warn ! ( self log " " local_addr e ) ; Err ( TransportErrorCode :: ServerSocketListenFailed ) } } }
Sets up the server side socket with the node IP:port
Sets up the server side socket with the node IP : port
&self
local_addr
&SocketAddr