fn spawn(
        ctx: C,
        properties: SocketWorkerProperties,
        events: psocket::DatagramSocketRequestStream,
    ) -> Result<(), libc::c_int> {
        let (local_event, peer_event) = zx::EventPair::create().map_err(|_| libc::ENOBUFS)?;
        // signal peer that OUTGOING is available.
        // TODO(brunodalbo): We're currently not enforcing any sort of
        // flow-control for outgoing UDP datagrams. That'll get fixed once we
        // limit the number of in flight datagrams per socket (i.e. application
        // buffers).
        if let Err(e) = local_event.signal_peer(zx::Signals::NONE, ZXSIO_SIGNAL_OUTGOING) {
            error!("UDP socket failed to signal peer: {:?}", e);
        }
        fasync::spawn(
            async move {
                let id = {
                    let mut locked = ctx.lock().await;
                    I::get_collection_mut(locked.dispatcher_mut())
                        .binding_data
                        .push(BindingData::<I>::new(local_event, peer_event, properties))
                };
                let worker = Self { ctx, id, _marker: std::marker::PhantomData };

                let result = events.try_for_each(|req| worker.handle_request(req).map(Ok)).await;

                let mut handler = worker.make_handler().await;
                let inner = handler.get_state_mut();
                if inner.ref_count == 1 {
                    // always make sure the socket is closed with core.
                    handler.close_core();
                    I::get_collection_mut(handler.ctx.dispatcher_mut())
                        .binding_data
                        .remove(worker.id)
                        .unwrap();
                } else {
                    inner.ref_count -= 1;
                }

                result
            }
            // When the closure above finishes, that means `self` goes out
            // of scope and is dropped, meaning that the event stream's
            // underlying channel is closed.
            // If any errors occured as a result of the closure, we just log
            // them.
            .unwrap_or_else(|e: fidl::Error| error!("UDP socket control request error: {:?}", e)),
        );
        Ok(())
    }
/// Starts servicing events from the provided event stream.
Starts servicing events from the provided event stream.
Starts servicing events from the provided event stream .
fn spawn(
        ctx: C,
        properties: SocketWorkerProperties,
        events: psocket::DatagramSocketRequestStream,
    ) -> Result<(), libc::c_int> {
        let (local_event, peer_event) = zx::EventPair::create().map_err(|_| libc::ENOBUFS)?;
        // signal peer that OUTGOING is available.
        // TODO(brunodalbo): We're currently not enforcing any sort of
        // flow-control for outgoing UDP datagrams. That'll get fixed once we
        // limit the number of in flight datagrams per socket (i.e. application
        // buffers).
        if let Err(e) = local_event.signal_peer(zx::Signals::NONE, ZXSIO_SIGNAL_OUTGOING) {
            error!("UDP socket failed to signal peer: {:?}", e);
        }
        fasync::spawn(
            async move {
                let id = {
                    let mut locked = ctx.lock().await;
                    I::get_collection_mut(locked.dispatcher_mut())
                        .binding_data
                        .push(BindingData::<I>::new(local_event, peer_event, properties))
                };
                let worker = Self { ctx, id, _marker: std::marker::PhantomData };
                let result = events.try_for_each(|req| worker.handle_request(req).map(Ok)).await;
                let mut handler = worker.make_handler().await;
                let inner = handler.get_state_mut();
                if inner.ref_count == 1 {
                    // always make sure the socket is closed with core.
                    handler.close_core();
                    I::get_collection_mut(handler.ctx.dispatcher_mut())
                        .binding_data
                        .remove(worker.id)
                        .unwrap();
                } else {
                    inner.ref_count -= 1;
                }
                result
            }
            // When the closure above finishes, that means `self` goes out
            // of scope and is dropped, meaning that the event stream's
            // underlying channel is closed.
            // If any errors occured as a result of the closure, we just log
            // them.
            .unwrap_or_else(|e: fidl::Error| error!("UDP socket control request error: {:?}", e)),
        );
        Ok(())
    }
fn spawn ( ctx : C , properties : SocketWorkerProperties , events : psocket :: DatagramSocketRequestStream , ) -> Result < ( ) , libc :: c_int > { let ( local_event , peer_event ) = zx :: EventPair :: create ( ) . map_err ( | _ | libc :: ENOBUFS ) ? ; // signal peer that OUTGOING is available. // TODO(brunodalbo): We're currently not enforcing any sort of // flow-control for outgoing UDP datagrams. That'll get fixed once we // limit the number of in flight datagrams per socket (i.e. application // buffers). if let Err ( e ) = local_event . signal_peer ( zx :: Signals :: NONE , ZXSIO_SIGNAL_OUTGOING ) { error ! ( " " e ) ; } fasync :: spawn ( async move { let id = { let mut locked = ctx . lock ( ) . await ; I :: get_collection_mut ( locked . dispatcher_mut ( ) ) . binding_data . push ( BindingData :: < I > :: new ( local_event , peer_event , properties ) ) } ; let worker = Self { ctx , id , _marker : std :: marker :: PhantomData } ; let result = events . try_for_each ( | req | worker . handle_request ( req ) . map ( Ok ) ) . await ; let mut handler = worker . make_handler ( ) . await ; let inner = handler . get_state_mut ( ) ; if inner . ref_count == 1 { // always make sure the socket is closed with core. handler . close_core ( ) ; I :: get_collection_mut ( handler . ctx . dispatcher_mut ( ) ) . binding_data . remove ( worker . id ) . unwrap ( ) ; } else { inner . ref_count -= 1 ; } result } // When the closure above finishes, that means `self` goes out // of scope and is dropped, meaning that the event stream's // underlying channel is closed. // If any errors occured as a result of the closure, we just log // them. . unwrap_or_else ( | e : fidl :: Error | error ! ( " " e ) ) , ) ; Ok ( ( ) ) }
Starts servicing events from the provided event stream.
Starts servicing events from the provided event stream .
ctx
C
properties
SocketWorkerProperties
events
psocket::DatagramSocketRequestStream
ctx
C
properties
SocketWorkerProperties
events
psocket::DatagramSocketRequestStream