fn start_make_connection_task(peer: Arc<RwLock<RemotePeer>>) {
    let peer = peer.clone();

    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.clone(), peer_guard.profile_svc.clone())
        };

        match profile_service.connect_to_device(&peer_id, PSM_AVCTP as u16).await {
            Ok(socket) => {
                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) => {
                            peer_guard.reset_connection(false);
                            fx_log_err!("Unable to make peer from socket {}: {:?}", peer_id, e);
                        }
                    },
                    _ => {
                        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);
                    }
                };
            }
            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);
                }
            }
        }
    })
}
/// 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>>) {
    let peer = peer.clone();
    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.clone(), peer_guard.profile_svc.clone())
        };
        match profile_service.connect_to_device(&peer_id, PSM_AVCTP as u16).await {
            Ok(socket) => {
                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) => {
                            peer_guard.reset_connection(false);
                            fx_log_err!("Unable to make peer from socket {}: {:?}", peer_id, e);
                        }
                    },
                    _ => {
                        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);
                    }
                };
            }
            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 > > ) { let peer = peer . clone ( ) ; 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 . clone ( ) , peer_guard . profile_svc . clone ( ) ) } ; match profile_service . connect_to_device ( & peer_id , PSM_AVCTP as u16 ) . await { Ok ( socket ) => { 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 ) => { peer_guard . reset_connection ( false ) ; fx_log_err ! ( " " peer_id e ) ; } } , _ => { 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 ) ; } } ; } 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>>
peer
Arc<RwLock<RemotePeer>>