pub async fn serve(self) -> Result<(), anyhow::Error> {
        use anyhow::Context as _;

        debug!("Serving netstack");
        self.spawn_timers().await;
        let mut fs = ServiceFs::new_local();
        let _: &mut ServiceFsDir<'_, _> = fs
            .dir("svc")
            .add_fidl_service(Service::Stack)
            .add_fidl_service(Service::Socket)
            .add_fidl_service(Service::Interfaces);

        let services = fs.take_and_serve_directory_handle().context("directory handle")?;
        let (work_items, tasks) = {
            let (sender, receiver) = mpsc::unbounded();
            (
                futures::stream::select(
                    receiver.map(WorkItem::Spawned),
                    services.map(WorkItem::Incoming),
                ),
                sender,
            )
        };
        let () = work_items
            .for_each_concurrent(None, |wi| async {
                match wi {
                    WorkItem::Incoming(Service::Stack(stack)) => {
                        stack
                            .serve_with(|rs| {
                                stack_fidl_worker::StackFidlWorker::serve(self.clone(), rs)
                            })
                            .await
                    }
                    WorkItem::Incoming(Service::Socket(socket)) => {
                        socket.serve_with(|rs| socket::serve(self.clone(), rs)).await
                    }
                    WorkItem::Incoming(Service::Interfaces(interfaces)) => {
                        interfaces
                            .serve_with(|rs| {
                                interfaces_watcher::serve(
                                    self.clone(),
                                    rs,
                                    tasks.clone().with(|w| {
                                        futures::future::ok::<_, futures::channel::mpsc::SendError>(
                                            Task::Watcher(w),
                                        )
                                    }),
                                )
                            })
                            .await
                    }
                    WorkItem::Spawned(Task::Watcher(watcher)) => {
                        watcher.await.unwrap_or_else(|err| {
                            log::error!("fuchsia.net.interfaces.Watcher error: {}", err)
                        })
                    }
                }
            })
            .await;
        debug!("Services stream finished");
        Ok(())
    }
/// Consumes the netstack and starts serving all the FIDL services it
/// implements to the outgoing service directory.
Consumes the netstack and starts serving all the FIDL services it
implements to the outgoing service directory.
Consumes the netstack and starts serving all the FIDL services it implements to the outgoing service directory .
pub async fn serve(self) -> Result<(), anyhow::Error> {
        use anyhow::Context as _;
        debug!("Serving netstack");
        self.spawn_timers().await;
        let mut fs = ServiceFs::new_local();
        let _: &mut ServiceFsDir<'_, _> = fs
            .dir("svc")
            .add_fidl_service(Service::Stack)
            .add_fidl_service(Service::Socket)
            .add_fidl_service(Service::Interfaces);
        let services = fs.take_and_serve_directory_handle().context("directory handle")?;
        let (work_items, tasks) = {
            let (sender, receiver) = mpsc::unbounded();
            (
                futures::stream::select(
                    receiver.map(WorkItem::Spawned),
                    services.map(WorkItem::Incoming),
                ),
                sender,
            )
        };
        let () = work_items
            .for_each_concurrent(None, |wi| async {
                match wi {
                    WorkItem::Incoming(Service::Stack(stack)) => {
                        stack
                            .serve_with(|rs| {
                                stack_fidl_worker::StackFidlWorker::serve(self.clone(), rs)
                            })
                            .await
                    }
                    WorkItem::Incoming(Service::Socket(socket)) => {
                        socket.serve_with(|rs| socket::serve(self.clone(), rs)).await
                    }
                    WorkItem::Incoming(Service::Interfaces(interfaces)) => {
                        interfaces
                            .serve_with(|rs| {
                                interfaces_watcher::serve(
                                    self.clone(),
                                    rs,
                                    tasks.clone().with(|w| {
                                        futures::future::ok::<_, futures::channel::mpsc::SendError>(
                                            Task::Watcher(w),
                                        )
                                    }),
                                )
                            })
                            .await
                    }
                    WorkItem::Spawned(Task::Watcher(watcher)) => {
                        watcher.await.unwrap_or_else(|err| {
                            log::error!("fuchsia.net.interfaces.Watcher error: {}", err)
                        })
                    }
                }
            })
            .await;
        debug!("Services stream finished");
        Ok(())
    }
pub async fn serve ( self ) -> Result < ( ) , anyhow :: Error > { use anyhow :: Context as _ ; debug ! ( " " ) ; self . spawn_timers ( ) . await ; let mut fs = ServiceFs :: new_local ( ) ; let _ : & mut ServiceFsDir < ' _ , _ > = fs . dir ( " " ) . add_fidl_service ( Service :: Stack ) . add_fidl_service ( Service :: Socket ) . add_fidl_service ( Service :: Interfaces ) ; let services = fs . take_and_serve_directory_handle ( ) . context ( " " ) ? ; let ( work_items , tasks ) = { let ( sender , receiver ) = mpsc :: unbounded ( ) ; ( futures :: stream :: select ( receiver . map ( WorkItem :: Spawned ) , services . map ( WorkItem :: Incoming ) , ) , sender , ) } ; let ( ) = work_items . for_each_concurrent ( None , | wi | async { match wi { WorkItem :: Incoming ( Service :: Stack ( stack ) ) => { stack . serve_with ( | rs | { stack_fidl_worker :: StackFidlWorker :: serve ( self . clone ( ) , rs ) } ) . await } WorkItem :: Incoming ( Service :: Socket ( socket ) ) => { socket . serve_with ( | rs | socket :: serve ( self . clone ( ) , rs ) ) . await } WorkItem :: Incoming ( Service :: Interfaces ( interfaces ) ) => { interfaces . serve_with ( | rs | { interfaces_watcher :: serve ( self . clone ( ) , rs , tasks . clone ( ) . with ( | w | { futures :: future :: ok :: < _ , futures :: channel :: mpsc :: SendError > ( Task :: Watcher ( w ) , ) } ) , ) } ) . await } WorkItem :: Spawned ( Task :: Watcher ( watcher ) ) => { watcher . await . unwrap_or_else ( | err | { log :: error ! ( " " err ) } ) } } } ) . await ; debug ! ( " " ) ; Ok ( ( ) ) }
Consumes the netstack and starts serving all the FIDL services it
implements to the outgoing service directory.
Consumes the netstack and starts serving all the FIDL services it implements to the outgoing service directory .
self
self