pub async fn forward_one_connection(&self) -> Result<()> {
        // Wait for a connection on the UNIX socket (connection from zxdb).
        // Accept this first, otherwise zxdb will hang forever on connecting.
        let (unix_conn, _) = self.unix_socket.accept().await?;

        // Create a FIDL socket to the debug_agent on the device.
        let (fidl_left, fidl_right) = fidl::Socket::create(fidl::SocketOpts::STREAM)
            .map_err(|s| anyhow!("Failed while creating socket: {}", s))?;
        Status::ok(self.debugger_proxy.connect(fidl_right).await?)?;
        let fidl_conn = fidl::AsyncSocket::from_socket(fidl_left)?;

        let (mut unix_rx, mut unix_tx) = unix_conn.split();
        let (mut fidl_rx, mut fidl_tx) = fidl_conn.split();

        // Forward from UNIX socket to FIDL socket.
        let unix_to_fidl = async {
            let mut buffer = [0; 4096];
            loop {
                let n = unix_rx.read(&mut buffer).await?;
                if n == 0 {
                    return Ok(()) as Result<()>;
                }
                let mut ofs = 0;
                while ofs != n {
                    let wrote = fidl_tx.write(&buffer[ofs..n]).await?;
                    ofs += wrote;
                    if wrote == 0 {
                        return Ok(()) as Result<()>;
                    }
                }
            }
        };

        // Forward from FIDL socket to UNIX socket.
        let fidl_to_unix = async {
            let mut buffer = [0; 4096];
            loop {
                let n = fidl_rx.read(&mut buffer).await?;
                if n == 0 {
                    return Ok(()) as Result<()>;
                }
                let mut ofs = 0;
                while ofs != n {
                    let wrote = unix_tx.write(&buffer[ofs..n]).await?;
                    ofs += wrote;
                    if wrote == 0 {
                        return Ok(()) as Result<()>;
                    }
                }
            }
        };

        // Exit on close or any error.
        futures::select! {
            res = unix_to_fidl.fuse() => res?,
            res = fidl_to_unix.fuse() => res?,
        };

        Ok(())
    }
/// Create, accept and start forwarding one connection. The call is blocking until the
/// connection closes, either by the remote debug_agent or by the local zxdb.
Create, accept and start forwarding one connection. The call is blocking until the
connection closes, either by the remote debug_agent or by the local zxdb.
Create accept and start forwarding one connection . The call is blocking until the connection closes either by the remote debug_agent or by the local zxdb .
pub async fn forward_one_connection(&self) -> Result<()> {
        // Wait for a connection on the UNIX socket (connection from zxdb).
        // Accept this first, otherwise zxdb will hang forever on connecting.
        let (unix_conn, _) = self.unix_socket.accept().await?;
        // Create a FIDL socket to the debug_agent on the device.
        let (fidl_left, fidl_right) = fidl::Socket::create(fidl::SocketOpts::STREAM)
            .map_err(|s| anyhow!("Failed while creating socket: {}", s))?;
        Status::ok(self.debugger_proxy.connect(fidl_right).await?)?;
        let fidl_conn = fidl::AsyncSocket::from_socket(fidl_left)?;
        let (mut unix_rx, mut unix_tx) = unix_conn.split();
        let (mut fidl_rx, mut fidl_tx) = fidl_conn.split();
        // Forward from UNIX socket to FIDL socket.
        let unix_to_fidl = async {
            let mut buffer = [0; 4096];
            loop {
                let n = unix_rx.read(&mut buffer).await?;
                if n == 0 {
                    return Ok(()) as Result<()>;
                }
                let mut ofs = 0;
                while ofs != n {
                    let wrote = fidl_tx.write(&buffer[ofs..n]).await?;
                    ofs += wrote;
                    if wrote == 0 {
                        return Ok(()) as Result<()>;
                    }
                }
            }
        };
        // Forward from FIDL socket to UNIX socket.
        let fidl_to_unix = async {
            let mut buffer = [0; 4096];
            loop {
                let n = fidl_rx.read(&mut buffer).await?;
                if n == 0 {
                    return Ok(()) as Result<()>;
                }
                let mut ofs = 0;
                while ofs != n {
                    let wrote = unix_tx.write(&buffer[ofs..n]).await?;
                    ofs += wrote;
                    if wrote == 0 {
                        return Ok(()) as Result<()>;
                    }
                }
            }
        };
        // Exit on close or any error.
        futures::select! {
            res = unix_to_fidl.fuse() => res?,
            res = fidl_to_unix.fuse() => res?,
        };
        Ok(())
    }
pub async fn forward_one_connection ( & self ) -> Result < ( ) > { // Wait for a connection on the UNIX socket (connection from zxdb). // Accept this first, otherwise zxdb will hang forever on connecting. let ( unix_conn , _ ) = self . unix_socket . accept ( ) . await ? ; // Create a FIDL socket to the debug_agent on the device. let ( fidl_left , fidl_right ) = fidl :: Socket :: create ( fidl :: SocketOpts :: STREAM ) . map_err ( | s | anyhow ! ( " " s ) ) ? ; Status :: ok ( self . debugger_proxy . connect ( fidl_right ) . await ? ) ? ; let fidl_conn = fidl :: AsyncSocket :: from_socket ( fidl_left ) ? ; let ( mut unix_rx , mut unix_tx ) = unix_conn . split ( ) ; let ( mut fidl_rx , mut fidl_tx ) = fidl_conn . split ( ) ; // Forward from UNIX socket to FIDL socket. let unix_to_fidl = async { let mut buffer = [ 0 ; 4096 ] ; loop { let n = unix_rx . read ( & mut buffer ) . await ? ; if n == 0 { return Ok ( ( ) ) as Result < ( ) > ; } let mut ofs = 0 ; while ofs != n { let wrote = fidl_tx . write ( & buffer [ ofs .. n ] ) . await ? ; ofs += wrote ; if wrote == 0 { return Ok ( ( ) ) as Result < ( ) > ; } } } } ; // Forward from FIDL socket to UNIX socket. let fidl_to_unix = async { let mut buffer = [ 0 ; 4096 ] ; loop { let n = fidl_rx . read ( & mut buffer ) . await ? ; if n == 0 { return Ok ( ( ) ) as Result < ( ) > ; } let mut ofs = 0 ; while ofs != n { let wrote = unix_tx . write ( & buffer [ ofs .. n ] ) . await ? ; ofs += wrote ; if wrote == 0 { return Ok ( ( ) ) as Result < ( ) > ; } } } } ; // Exit on close or any error. futures :: select ! { res unix_to_fidl fuse ( ) res res fidl_to_unix fuse ( ) res } ; Ok ( ( ) ) }
Create, accept and start forwarding one connection.
Create accept and start forwarding one connection .
&self
&self