pub async fn rfcomm_channel_task(
    server_channel: ServerChannelNumber,
    state: Arc<RwLock<ProfileState>>,
    mut channel: Channel,
    mut write_requests: mpsc::Receiver<Vec<u8>>,
) {
    loop {
        select! {
            bytes_from_peer = channel.next().fuse() => {
                let user_data = match bytes_from_peer {
                    Some(Ok(bytes)) => bytes,
                    Some(Err(e)) => {
                        println!("Error receiving data: {:?}", e);
                        continue;
                    }
                    None => {
                        // RFCOMM channel closed by the peer.
                        println!("Peer closed RFCOMM channel {:?}", server_channel);
                        state.write().rfcomm.remove_channel(server_channel);
                        return;
                    }
                };
                println!("{:?}: Received user data from peer: {:?}", server_channel, user_data);
            }
            bytes_to_peer = write_requests.next() => {
                match bytes_to_peer {
                    Some(bytes) => {
                        let res = channel.as_ref().write(&bytes);
                        println!("{:?}: Sent user data to peer: {:?}", server_channel, res);
                    }
                    None => return, // RFCOMM channel closed by tool.
                }
            }
            complete => return,
        }
    }
}
/// Processes data received from the remote peer over the provided RFCOMM `channel`.
/// Processes data in the `write_requests` queue to be sent to the remote peer.
Processes data received from the remote peer over the provided RFCOMM `channel`.
Processes data in the `write_requests` queue to be sent to the remote peer.
Processes data received from the remote peer over the provided RFCOMM ` channel ` . Processes data in the ` write_requests ` queue to be sent to the remote peer .
pub async fn rfcomm_channel_task(
    server_channel: ServerChannelNumber,
    state: Arc<RwLock<ProfileState>>,
    mut channel: Channel,
    mut write_requests: mpsc::Receiver<Vec<u8>>,
) {
    loop {
        select! {
            bytes_from_peer = channel.next().fuse() => {
                let user_data = match bytes_from_peer {
                    Some(Ok(bytes)) => bytes,
                    Some(Err(e)) => {
                        println!("Error receiving data: {:?}", e);
                        continue;
                    }
                    None => {
                        // RFCOMM channel closed by the peer.
                        println!("Peer closed RFCOMM channel {:?}", server_channel);
                        state.write().rfcomm.remove_channel(server_channel);
                        return;
                    }
                };
                println!("{:?}: Received user data from peer: {:?}", server_channel, user_data);
            }
            bytes_to_peer = write_requests.next() => {
                match bytes_to_peer {
                    Some(bytes) => {
                        let res = channel.as_ref().write(&bytes);
                        println!("{:?}: Sent user data to peer: {:?}", server_channel, res);
                    }
                    None => return, // RFCOMM channel closed by tool.
                }
            }
            complete => return,
        }
    }
}
pub async fn rfcomm_channel_task ( server_channel : ServerChannelNumber , state : Arc < RwLock < ProfileState > > , mut channel : Channel , mut write_requests : mpsc :: Receiver < Vec < u8 > > , ) { loop { select ! { bytes_from_peer channel next ( ) fuse ( ) { let user_data match bytes_from_peer { Some ( Ok ( bytes ) ) bytes Some ( Err ( e ) ) { println ( " " e ) continue } None { // RFCOMM channel closed by the peer. println ( " " server_channel ) state write ( ) rfcomm remove_channel ( server_channel ) return } } println ( " " server_channel user_data ) } bytes_to_peer write_requests next ( ) { match bytes_to_peer { Some ( bytes ) { let res channel as_ref ( ) write ( bytes ) println ( " " server_channel res ) } None return // RFCOMM channel closed by tool. } } complete return } } }
Processes data received from the remote peer over the provided RFCOMM `channel`.
Processes data received from the remote peer over the provided RFCOMM ` channel ` .
server_channel
ServerChannelNumber
state
Arc<RwLock<ProfileState>>
channel
Channel
write_requests
mpsc::Receiver<Vec<u8>>
server_channel
ServerChannelNumber
state
Arc<RwLock<ProfileState>>
channel
Channel
write_requests
mpsc::Receiver<Vec<u8>>