/// Proxies data between the `display_socket` and `wayland_bridge`.
///
/// Note that this function loops until an error is encountered, so the caller is responsible for
/// any creating any necessary threads.
Proxies data between the `display_socket` and `wayland_bridge`.
Note that this function loops until an error is encountered, so the caller is responsible for
any creating any necessary threads.
Proxies data between the ` display_socket ` and ` wayland_bridge ` . Note that this function loops until an error is encountered so the caller is responsible for any creating any necessary threads .
fn serve_display_socket(
    kernel: Weak<Kernel>,
    display_socket: SocketHandle,
    mut wayland_bridge: zx::Channel,
) -> Result<(), Errno> {
    let waiter = Waiter::new();
    let socket = loop {
        if let Ok(socket) = display_socket.accept(ucred::default()) {
            break socket;
        }
    };
    loop {
        let kernel = match kernel.upgrade() {
            Some(kernel) => kernel,
            None => {
                log::error!("Kernel no longer alive, returning.");
                return error!(ENOMEM);
            }
        };
        send_to_wayland(&socket, &mut wayland_bridge)?;
        send_to_client(&socket, &mut wayland_bridge, &kernel)?;
        wait_async(&socket, &wayland_bridge, &waiter);
        // Drain all the packets from the port, since we just read/write in both directions on each
        // wake we don't care about the exact event that triggered the wake.
        // TODO: This should be fixed to either use a callback per direction of communication (so
        // that we only queue one packet per event), or waiter needs to be refactored to return an
        // array of events (and dequeue more than one port packet at a time).
        let mut deadline = zx::Time::INFINITE;
        loop {
            match waiter.wait_kernel(deadline) {
                Ok(_) => {}
                Err(e) if e == ETIMEDOUT => {
                    break;
                }
                err => return err,
            }
            deadline = zx::Time::ZERO;
        }
    }
}
fn serve_display_socket ( kernel : Weak < Kernel > , display_socket : SocketHandle , mut wayland_bridge : zx :: Channel , ) -> Result < ( ) , Errno > { let waiter = Waiter :: new ( ) ; let socket = loop { if let Ok ( socket ) = display_socket . accept ( ucred :: default ( ) ) { break socket ; } } ; loop { let kernel = match kernel . upgrade ( ) { Some ( kernel ) => kernel , None => { log :: error ! ( " " ) ; return error ! ( ENOMEM ) ; } } ; send_to_wayland ( & socket , & mut wayland_bridge ) ? ; send_to_client ( & socket , & mut wayland_bridge , & kernel ) ? ; wait_async ( & socket , & wayland_bridge , & waiter ) ; // Drain all the packets from the port, since we just read/write in both directions on each // wake we don't care about the exact event that triggered the wake. // TODO: This should be fixed to either use a callback per direction of communication (so // that we only queue one packet per event), or waiter needs to be refactored to return an // array of events (and dequeue more than one port packet at a time). let mut deadline = zx :: Time :: INFINITE ; loop { match waiter . wait_kernel ( deadline ) { Ok ( _ ) => { } Err ( e ) if e == ETIMEDOUT => { break ; } err => return err , } deadline = zx :: Time :: ZERO ; } } }
Proxies data between the `display_socket` and `wayland_bridge`.
Proxies data between the ` display_socket ` and ` wayland_bridge ` .
kernel
Weak<Kernel>
display_socket
SocketHandle
wayland_bridge
zx::Channel