fn connect(mut self, addr: Vec<u8>) -> Result<(), libc::c_int> {
        let sockaddr = I::SocketAddress::parse(addr.as_slice()).ok_or(libc::EFAULT)?;
        trace!("connect UDP sockaddr: {:?}", sockaddr);
        if sockaddr.family() != I::SocketAddress::FAMILY {
            return Err(libc::EAFNOSUPPORT);
        }
        let remote_port = sockaddr.get_specified_port().ok_or(libc::ECONNREFUSED)?;
        let remote_addr = sockaddr.get_specified_addr().ok_or(libc::EINVAL)?;

        let (local_addr, local_port) = match self.get_state().info.state {
            SocketState::Unbound => {
                // do nothing, we're already unbound.
                // return None for local_addr and local_port.
                (None, None)
            }
            SocketState::BoundListen { listener_id } => {
                // if we're bound to a listen mode, we need to remove the
                // listener, and retrieve the bound local addr and port.
                let list_info = remove_udp_listener(self.ctx.deref_mut(), listener_id);
                // also remove from the EventLoop context:
                I::get_collection_mut(self.ctx.dispatcher_mut())
                    .listeners
                    .remove(&listener_id)
                    .unwrap();

                (list_info.local_ip, Some(list_info.local_port))
            }
            SocketState::BoundConnect { conn_id } => {
                // if we're bound to a connect mode, we need to remove the
                // connection, and retrieve the bound local addr and port.
                let conn_info = remove_udp_conn(self.ctx.deref_mut(), conn_id);
                // also remove from the EventLoop context:
                I::get_collection_mut(self.ctx.dispatcher_mut()).conns.remove(&conn_id).unwrap();
                (Some(conn_info.local_ip), Some(conn_info.local_port))
            }
        };

        let conn_id =
            connect_udp(self.ctx.deref_mut(), local_addr, local_port, remote_addr, remote_port)
                .map_err(IntoErrno::into_errno)?;

        self.get_state_mut().info.state = SocketState::BoundConnect { conn_id };
        I::get_collection_mut(self.ctx.dispatcher_mut()).conns.insert(&conn_id, self.binding_id);
        Ok(())
    }
/// Handles a [POSIX socket connect request].
///
/// [POSIX socket connect request]: psocket::DatagramSocketRequest::Connect
Handles a [POSIX socket connect request].
Handles a [ POSIX socket connect request ] .
fn connect(mut self, addr: Vec<u8>) -> Result<(), libc::c_int> {
        let sockaddr = I::SocketAddress::parse(addr.as_slice()).ok_or(libc::EFAULT)?;
        trace!("connect UDP sockaddr: {:?}", sockaddr);
        if sockaddr.family() != I::SocketAddress::FAMILY {
            return Err(libc::EAFNOSUPPORT);
        }
        let remote_port = sockaddr.get_specified_port().ok_or(libc::ECONNREFUSED)?;
        let remote_addr = sockaddr.get_specified_addr().ok_or(libc::EINVAL)?;
        let (local_addr, local_port) = match self.get_state().info.state {
            SocketState::Unbound => {
                // do nothing, we're already unbound.
                // return None for local_addr and local_port.
                (None, None)
            }
            SocketState::BoundListen { listener_id } => {
                // if we're bound to a listen mode, we need to remove the
                // listener, and retrieve the bound local addr and port.
                let list_info = remove_udp_listener(self.ctx.deref_mut(), listener_id);
                // also remove from the EventLoop context:
                I::get_collection_mut(self.ctx.dispatcher_mut())
                    .listeners
                    .remove(&listener_id)
                    .unwrap();
                (list_info.local_ip, Some(list_info.local_port))
            }
            SocketState::BoundConnect { conn_id } => {
                // if we're bound to a connect mode, we need to remove the
                // connection, and retrieve the bound local addr and port.
                let conn_info = remove_udp_conn(self.ctx.deref_mut(), conn_id);
                // also remove from the EventLoop context:
                I::get_collection_mut(self.ctx.dispatcher_mut()).conns.remove(&conn_id).unwrap();
                (Some(conn_info.local_ip), Some(conn_info.local_port))
            }
        };
        let conn_id =
            connect_udp(self.ctx.deref_mut(), local_addr, local_port, remote_addr, remote_port)
                .map_err(IntoErrno::into_errno)?;
        self.get_state_mut().info.state = SocketState::BoundConnect { conn_id };
        I::get_collection_mut(self.ctx.dispatcher_mut()).conns.insert(&conn_id, self.binding_id);
        Ok(())
    }
fn connect ( mut self , addr : Vec < u8 > ) -> Result < ( ) , libc :: c_int > { let sockaddr = I :: SocketAddress :: parse ( addr . as_slice ( ) ) . ok_or ( libc :: EFAULT ) ? ; trace ! ( " " sockaddr ) ; if sockaddr . family ( ) != I :: SocketAddress :: FAMILY { return Err ( libc :: EAFNOSUPPORT ) ; } let remote_port = sockaddr . get_specified_port ( ) . ok_or ( libc :: ECONNREFUSED ) ? ; let remote_addr = sockaddr . get_specified_addr ( ) . ok_or ( libc :: EINVAL ) ? ; let ( local_addr , local_port ) = match self . get_state ( ) . info . state { SocketState :: Unbound => { // do nothing, we're already unbound. // return None for local_addr and local_port. ( None , None ) } SocketState :: BoundListen { listener_id } => { // if we're bound to a listen mode, we need to remove the // listener, and retrieve the bound local addr and port. let list_info = remove_udp_listener ( self . ctx . deref_mut ( ) , listener_id ) ; // also remove from the EventLoop context: I :: get_collection_mut ( self . ctx . dispatcher_mut ( ) ) . listeners . remove ( & listener_id ) . unwrap ( ) ; ( list_info . local_ip , Some ( list_info . local_port ) ) } SocketState :: BoundConnect { conn_id } => { // if we're bound to a connect mode, we need to remove the // connection, and retrieve the bound local addr and port. let conn_info = remove_udp_conn ( self . ctx . deref_mut ( ) , conn_id ) ; // also remove from the EventLoop context: I :: get_collection_mut ( self . ctx . dispatcher_mut ( ) ) . conns . remove ( & conn_id ) . unwrap ( ) ; ( Some ( conn_info . local_ip ) , Some ( conn_info . local_port ) ) } } ; let conn_id = connect_udp ( self . ctx . deref_mut ( ) , local_addr , local_port , remote_addr , remote_port ) . map_err ( IntoErrno :: into_errno ) ? ; self . get_state_mut ( ) . info . state = SocketState :: BoundConnect { conn_id } ; I :: get_collection_mut ( self . ctx . dispatcher_mut ( ) ) . conns . insert ( & conn_id , self . binding_id ) ; Ok ( ( ) ) }
Handles a [POSIX socket connect request].
Handles a [ POSIX socket connect request ] .
mut self
addr
Vec<u8>
mut self
addr
Vec<u8>