/// Starts a task to attempt an outgoing L2CAP connection to remote's AVRCP control channel.
/// The control channel should be in `Connecting` state before spawning this task.
/// TODO(BT-2747): Fix a race where an incoming connection can come in while we are making an
///       outgoing connection. Properly handle the case where we are attempting to connect to remote
///       at the same time they make an incoming connection according to how the the spec says.
Starts a task to attempt an outgoing L2CAP connection to remote's AVRCP control channel.
The control channel should be in `Connecting` state before spawning this task.
TODO(BT-2747): Fix a race where an incoming connection can come in while we are making an
outgoing connection. Properly handle the case where we are attempting to connect to remote
at the same time they make an incoming connection according to how the the spec says.
Starts a task to attempt an outgoing L2CAP connection to remote ' s AVRCP control channel . The control channel should be in ` Connecting ` state before spawning this task . TODO ( BT - 2747 ) : Fix a race where an incoming connection can come in while we are making an outgoing connection . Properly handle the case where we are attempting to connect to remote at the same time they make an incoming connection according to how the the spec says .
fn start_make_connection_task(peer: Arc<RwLock<RemotePeer>>) {
    fasync::spawn(async move {
        let (peer_id, profile_service) = {
            let peer_guard = peer.read();
            // early return if we are not in `Connecting`
            match peer_guard.control_channel {
                PeerChannel::Connecting => {}
                _ => return,
            }
            (peer_guard.peer_id, peer_guard.profile_proxy.clone())
        };
        match profile_service
            .connect(&mut peer_id.into(), PSM_AVCTP, ChannelParameters::new_empty())
            .await
        {
            Err(fidl_err) => {
                let mut peer_guard = peer.write();
                fx_log_err!("FIDL error calling connect: {:?}", fidl_err);
                peer_guard.reset_connection(false);
            }
            Ok(Ok(channel)) => {
                let mut peer_guard = peer.write();
                if channel.socket.is_none() {
                    fx_log_err!("Connect didn't return a socket?!");
                    peer_guard.reset_connection(false);
                    return;
                }
                let socket = channel.socket.expect("socket isn't None");
                let mut peer_guard = peer.write();
                match peer_guard.control_channel {
                    PeerChannel::Connecting => match AvcPeer::new(socket) {
                        Ok(peer) => {
                            peer_guard.set_control_connection(peer);
                        }
                        Err(e) => {
                            fx_log_err!("Unable to make peer from socket {:?}: {:?}", peer_id, e);
                            peer_guard.reset_connection(false);
                        }
                    },
                    _ => {
                        fx_log_info!(
                            "incoming connection established while making outgoing {:?}",
                            peer_id
                        );
                        // an incoming l2cap connection was made while we were making an
                        // outgoing one. Drop both connections per spec.
                        peer_guard.reset_connection(false);
                    }
                };
            }
            Ok(Err(e)) => {
                fx_log_err!("connect_to_device error {}: {:?}", peer_id, e);
                let mut peer_guard = peer.write();
                if let PeerChannel::Connecting = peer_guard.control_channel {
                    peer_guard.reset_connection(false);
                }
            }
        }
    })
}
fn start_make_connection_task ( peer : Arc < RwLock < RemotePeer > > ) { fasync :: spawn ( async move { let ( peer_id , profile_service ) = { let peer_guard = peer . read ( ) ; // early return if we are not in `Connecting` match peer_guard . control_channel { PeerChannel :: Connecting => { } _ => return , } ( peer_guard . peer_id , peer_guard . profile_proxy . clone ( ) ) } ; match profile_service . connect ( & mut peer_id . into ( ) , PSM_AVCTP , ChannelParameters :: new_empty ( ) ) . await { Err ( fidl_err ) => { let mut peer_guard = peer . write ( ) ; fx_log_err ! ( " " fidl_err ) ; peer_guard . reset_connection ( false ) ; } Ok ( Ok ( channel ) ) => { let mut peer_guard = peer . write ( ) ; if channel . socket . is_none ( ) { fx_log_err ! ( " " ) ; peer_guard . reset_connection ( false ) ; return ; } let socket = channel . socket . expect ( " " ) ; let mut peer_guard = peer . write ( ) ; match peer_guard . control_channel { PeerChannel :: Connecting => match AvcPeer :: new ( socket ) { Ok ( peer ) => { peer_guard . set_control_connection ( peer ) ; } Err ( e ) => { fx_log_err ! ( " " peer_id e ) ; peer_guard . reset_connection ( false ) ; } } , _ => { fx_log_info ! ( " " peer_id ) ; // an incoming l2cap connection was made while we were making an // outgoing one. Drop both connections per spec. peer_guard . reset_connection ( false ) ; } } ; } Ok ( Err ( e ) ) => { fx_log_err ! ( " " peer_id e ) ; let mut peer_guard = peer . write ( ) ; if let PeerChannel :: Connecting = peer_guard . control_channel { peer_guard . reset_connection ( false ) ; } } } } ) }
Starts a task to attempt an outgoing L2CAP connection to remote's AVRCP control channel.
Starts a task to attempt an outgoing L2CAP connection to remote ' s AVRCP control channel .
peer
Arc<RwLock<RemotePeer>>