pub fn handle_server_message(server_socket: &CrasServerSocket) -> Result<ServerResult> {
        let message = CrasClientMessage::try_new(&server_socket)?;
        match message.get_id()? {
            CRAS_CLIENT_MESSAGE_ID::CRAS_CLIENT_CONNECTED => {
                let cmsg: &cras_client_connected = message.get_message()?;
                // CRAS server should return a shared memory area which contains
                // `cras_server_state`.
                let server_state_fd = unsafe { CrasServerStateShmFd::new(message.fds[0]) };
                Ok(ServerResult::Connected(cmsg.client_id, server_state_fd))
            }
            CRAS_CLIENT_MESSAGE_ID::CRAS_CLIENT_STREAM_CONNECTED => {
                let cmsg: &cras_client_stream_connected = message.get_message()?;
                // CRAS should return two shared memory areas the first which has
                // mem::size_of::<cras_audio_shm_header>() bytes, and the second which has
                // `samples_shm_size` bytes.
                Ok(ServerResult::StreamConnected(
                    cmsg.stream_id,
                    // Safe because CRAS ensures that the first fd contains a cras_audio_shm_header
                    unsafe { CrasAudioShmHeaderFd::new(message.fds[0]) },
                    // Safe because CRAS ensures that the second fd has length 'samples_shm_size'
                    unsafe { CrasShmFd::new(message.fds[1], cmsg.samples_shm_size as usize) },
                ))
            }
            CRAS_CLIENT_MESSAGE_ID::CRAS_CLIENT_AUDIO_DEBUG_INFO_READY => {
                Ok(ServerResult::DebugInfoReady)
            }
            _ => Err(Error::MessageTypeError),
        }
    }
/// Reads and handles one server message and converts `CrasClientMessage` into `ServerResult`
/// with error handling.
///
/// # Arguments
/// * `server_socket`: A reference to `CrasServerSocket`.
Reads and handles one server message and converts `CrasClientMessage` into `ServerResult`
with error handling.
Reads and handles one server message and converts ` CrasClientMessage ` into ` ServerResult ` with error handling .
pub fn handle_server_message(server_socket: &CrasServerSocket) -> Result<ServerResult> {
        let message = CrasClientMessage::try_new(&server_socket)?;
        match message.get_id()? {
            CRAS_CLIENT_MESSAGE_ID::CRAS_CLIENT_CONNECTED => {
                let cmsg: &cras_client_connected = message.get_message()?;
                // CRAS server should return a shared memory area which contains
                // `cras_server_state`.
                let server_state_fd = unsafe { CrasServerStateShmFd::new(message.fds[0]) };
                Ok(ServerResult::Connected(cmsg.client_id, server_state_fd))
            }
            CRAS_CLIENT_MESSAGE_ID::CRAS_CLIENT_STREAM_CONNECTED => {
                let cmsg: &cras_client_stream_connected = message.get_message()?;
                // CRAS should return two shared memory areas the first which has
                // mem::size_of::<cras_audio_shm_header>() bytes, and the second which has
                // `samples_shm_size` bytes.
                Ok(ServerResult::StreamConnected(
                    cmsg.stream_id,
                    // Safe because CRAS ensures that the first fd contains a cras_audio_shm_header
                    unsafe { CrasAudioShmHeaderFd::new(message.fds[0]) },
                    // Safe because CRAS ensures that the second fd has length 'samples_shm_size'
                    unsafe { CrasShmFd::new(message.fds[1], cmsg.samples_shm_size as usize) },
                ))
            }
            CRAS_CLIENT_MESSAGE_ID::CRAS_CLIENT_AUDIO_DEBUG_INFO_READY => {
                Ok(ServerResult::DebugInfoReady)
            }
            _ => Err(Error::MessageTypeError),
        }
    }
pub fn handle_server_message ( server_socket : & CrasServerSocket ) -> Result < ServerResult > { let message = CrasClientMessage :: try_new ( & server_socket ) ? ; match message . get_id ( ) ? { CRAS_CLIENT_MESSAGE_ID :: CRAS_CLIENT_CONNECTED => { let cmsg : & cras_client_connected = message . get_message ( ) ? ; // CRAS server should return a shared memory area which contains // `cras_server_state`. let server_state_fd = unsafe { CrasServerStateShmFd :: new ( message . fds [ 0 ] ) } ; Ok ( ServerResult :: Connected ( cmsg . client_id , server_state_fd ) ) } CRAS_CLIENT_MESSAGE_ID :: CRAS_CLIENT_STREAM_CONNECTED => { let cmsg : & cras_client_stream_connected = message . get_message ( ) ? ; // CRAS should return two shared memory areas the first which has // mem::size_of::<cras_audio_shm_header>() bytes, and the second which has // `samples_shm_size` bytes. Ok ( ServerResult :: StreamConnected ( cmsg . stream_id , // Safe because CRAS ensures that the first fd contains a cras_audio_shm_header unsafe { CrasAudioShmHeaderFd :: new ( message . fds [ 0 ] ) } , // Safe because CRAS ensures that the second fd has length 'samples_shm_size' unsafe { CrasShmFd :: new ( message . fds [ 1 ] , cmsg . samples_shm_size as usize ) } , ) ) } CRAS_CLIENT_MESSAGE_ID :: CRAS_CLIENT_AUDIO_DEBUG_INFO_READY => { Ok ( ServerResult :: DebugInfoReady ) } _ => Err ( Error :: MessageTypeError ) , } }
Reads and handles one server message and converts `CrasClientMessage` into `ServerResult`
with error handling.
Reads and handles one server message and converts ` CrasClientMessage ` into ` ServerResult ` with error handling .
server_socket
&CrasServerSocket
server_socket
&CrasServerSocket