fidl_fuchsia_net_sockets/
fidl_fuchsia_net_sockets.rs

1// WARNING: This file is machine generated by fidlgen.
2
3#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::client::QueryResponseFut;
8use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
9use fidl::endpoints::{ControlHandle as _, Responder as _};
10pub use fidl_fuchsia_net_sockets__common::*;
11use futures::future::{self, MaybeDone, TryFutureExt};
12use zx_status;
13
14#[derive(Debug, PartialEq)]
15pub struct DiagnosticsIterateIpRequest {
16    /// The `IpIterator` for streaming sockets back to the caller.
17    pub s: fidl::endpoints::ServerEnd<IpIteratorMarker>,
18    /// The types of extended information to request. Information is
19    /// only returned for qualifying sockets. For example, the `TCP_INFO`
20    /// extension has no effect on returned UDP sockets.
21    pub extensions: Extensions,
22    /// Filters to apply to all sockets on the system in Conjunctive Normal
23    /// Form. Only sockets matched by all filters are returned through the
24    /// `IpIterator` protocol.
25    ///
26    /// For example, if you want to match all IPv4 TCP sockets with a local
27    /// port of 22, but not on loopback, you could use the following query:
28    ///
29    /// [
30    ///   {
31    ///     family: Ipv4,
32    ///   },
33    ///   {
34    ///     proto: tcp {
35    ///       src_port: {
36    ///         start:  22,
37    ///         end:    22,
38    ///         invert: false,
39    ///       }
40    ///     },
41    ///   },
42    ///   {
43    ///     src_addr: {
44    ///       range: {
45    ///         start: "127.0.0.1"
46    ///         end:   "127.0.0.1"
47    ///       },
48    ///       invert: true
49    ///     },
50    ///   },
51    /// ]
52    pub matchers: Vec<IpSocketMatcher>,
53}
54
55impl fidl::Standalone<fidl::encoding::DefaultFuchsiaResourceDialect>
56    for DiagnosticsIterateIpRequest
57{
58}
59
60#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
61pub struct ControlMarker;
62
63impl fidl::endpoints::ProtocolMarker for ControlMarker {
64    type Proxy = ControlProxy;
65    type RequestStream = ControlRequestStream;
66    #[cfg(target_os = "fuchsia")]
67    type SynchronousProxy = ControlSynchronousProxy;
68
69    const DEBUG_NAME: &'static str = "fuchsia.net.sockets.Control";
70}
71impl fidl::endpoints::DiscoverableProtocolMarker for ControlMarker {}
72pub type ControlDisconnectIpResult = Result<u32, ControlDisconnectIpError>;
73
74pub trait ControlProxyInterface: Send + Sync {
75    type DisconnectIpResponseFut: std::future::Future<Output = Result<ControlDisconnectIpResult, fidl::Error>>
76        + Send;
77    fn r#disconnect_ip(
78        &self,
79        payload: &ControlDisconnectIpRequest,
80    ) -> Self::DisconnectIpResponseFut;
81}
82#[derive(Debug)]
83#[cfg(target_os = "fuchsia")]
84pub struct ControlSynchronousProxy {
85    client: fidl::client::sync::Client,
86}
87
88#[cfg(target_os = "fuchsia")]
89impl fidl::endpoints::SynchronousProxy for ControlSynchronousProxy {
90    type Proxy = ControlProxy;
91    type Protocol = ControlMarker;
92
93    fn from_channel(inner: fidl::Channel) -> Self {
94        Self::new(inner)
95    }
96
97    fn into_channel(self) -> fidl::Channel {
98        self.client.into_channel()
99    }
100
101    fn as_channel(&self) -> &fidl::Channel {
102        self.client.as_channel()
103    }
104}
105
106#[cfg(target_os = "fuchsia")]
107impl ControlSynchronousProxy {
108    pub fn new(channel: fidl::Channel) -> Self {
109        let protocol_name = <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
110        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
111    }
112
113    pub fn into_channel(self) -> fidl::Channel {
114        self.client.into_channel()
115    }
116
117    /// Waits until an event arrives and returns it. It is safe for other
118    /// threads to make concurrent requests while waiting for an event.
119    pub fn wait_for_event(
120        &self,
121        deadline: zx::MonotonicInstant,
122    ) -> Result<ControlEvent, fidl::Error> {
123        ControlEvent::decode(self.client.wait_for_event(deadline)?)
124    }
125
126    /// Disconnect the socket matched by the provided matchers. See
127    /// `Diagnostics.IterateIp` for matcher semantics.
128    ///
129    /// Disconnecting a socket depends on the transport protocol. In all cases,
130    /// all further operations on the socket will return `ECONNABORTED`:
131    ///
132    /// - UDP: the behavior is equivalent to calling
133    ///   `fuchsia.posix.socket/*.Disconnect`. Any destination port and address,
134    ///   and bound device are removed.
135    /// - TCP LISTEN state: TCP moves to state CLOSE. All non-accepted sockets
136    ///   are closed and an RST is sent to the peer.
137    /// - TCP all other states: The TCP connection is put in state CLOSE and an
138    ///   RST is sent to the remote peer, if required.
139    ///
140    /// If no filters are specified, or the provided filters match all sockets,
141    /// an error is returned and no action is taken.
142    pub fn r#disconnect_ip(
143        &self,
144        mut payload: &ControlDisconnectIpRequest,
145        ___deadline: zx::MonotonicInstant,
146    ) -> Result<ControlDisconnectIpResult, fidl::Error> {
147        let _response =
148            self.client.send_query::<ControlDisconnectIpRequest, fidl::encoding::ResultType<
149                ControlDisconnectIpResponse,
150                ControlDisconnectIpError,
151            >>(
152                payload,
153                0xbdaa66fbb4241a4,
154                fidl::encoding::DynamicFlags::empty(),
155                ___deadline,
156            )?;
157        Ok(_response.map(|x| x.disconnected))
158    }
159}
160
161#[cfg(target_os = "fuchsia")]
162impl From<ControlSynchronousProxy> for zx::Handle {
163    fn from(value: ControlSynchronousProxy) -> Self {
164        value.into_channel().into()
165    }
166}
167
168#[cfg(target_os = "fuchsia")]
169impl From<fidl::Channel> for ControlSynchronousProxy {
170    fn from(value: fidl::Channel) -> Self {
171        Self::new(value)
172    }
173}
174
175#[cfg(target_os = "fuchsia")]
176impl fidl::endpoints::FromClient for ControlSynchronousProxy {
177    type Protocol = ControlMarker;
178
179    fn from_client(value: fidl::endpoints::ClientEnd<ControlMarker>) -> Self {
180        Self::new(value.into_channel())
181    }
182}
183
184#[derive(Debug, Clone)]
185pub struct ControlProxy {
186    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
187}
188
189impl fidl::endpoints::Proxy for ControlProxy {
190    type Protocol = ControlMarker;
191
192    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
193        Self::new(inner)
194    }
195
196    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
197        self.client.into_channel().map_err(|client| Self { client })
198    }
199
200    fn as_channel(&self) -> &::fidl::AsyncChannel {
201        self.client.as_channel()
202    }
203}
204
205impl ControlProxy {
206    /// Create a new Proxy for fuchsia.net.sockets/Control.
207    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
208        let protocol_name = <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
209        Self { client: fidl::client::Client::new(channel, protocol_name) }
210    }
211
212    /// Get a Stream of events from the remote end of the protocol.
213    ///
214    /// # Panics
215    ///
216    /// Panics if the event stream was already taken.
217    pub fn take_event_stream(&self) -> ControlEventStream {
218        ControlEventStream { event_receiver: self.client.take_event_receiver() }
219    }
220
221    /// Disconnect the socket matched by the provided matchers. See
222    /// `Diagnostics.IterateIp` for matcher semantics.
223    ///
224    /// Disconnecting a socket depends on the transport protocol. In all cases,
225    /// all further operations on the socket will return `ECONNABORTED`:
226    ///
227    /// - UDP: the behavior is equivalent to calling
228    ///   `fuchsia.posix.socket/*.Disconnect`. Any destination port and address,
229    ///   and bound device are removed.
230    /// - TCP LISTEN state: TCP moves to state CLOSE. All non-accepted sockets
231    ///   are closed and an RST is sent to the peer.
232    /// - TCP all other states: The TCP connection is put in state CLOSE and an
233    ///   RST is sent to the remote peer, if required.
234    ///
235    /// If no filters are specified, or the provided filters match all sockets,
236    /// an error is returned and no action is taken.
237    pub fn r#disconnect_ip(
238        &self,
239        mut payload: &ControlDisconnectIpRequest,
240    ) -> fidl::client::QueryResponseFut<
241        ControlDisconnectIpResult,
242        fidl::encoding::DefaultFuchsiaResourceDialect,
243    > {
244        ControlProxyInterface::r#disconnect_ip(self, payload)
245    }
246}
247
248impl ControlProxyInterface for ControlProxy {
249    type DisconnectIpResponseFut = fidl::client::QueryResponseFut<
250        ControlDisconnectIpResult,
251        fidl::encoding::DefaultFuchsiaResourceDialect,
252    >;
253    fn r#disconnect_ip(
254        &self,
255        mut payload: &ControlDisconnectIpRequest,
256    ) -> Self::DisconnectIpResponseFut {
257        fn _decode(
258            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
259        ) -> Result<ControlDisconnectIpResult, fidl::Error> {
260            let _response = fidl::client::decode_transaction_body::<
261                fidl::encoding::ResultType<ControlDisconnectIpResponse, ControlDisconnectIpError>,
262                fidl::encoding::DefaultFuchsiaResourceDialect,
263                0xbdaa66fbb4241a4,
264            >(_buf?)?;
265            Ok(_response.map(|x| x.disconnected))
266        }
267        self.client.send_query_and_decode::<ControlDisconnectIpRequest, ControlDisconnectIpResult>(
268            payload,
269            0xbdaa66fbb4241a4,
270            fidl::encoding::DynamicFlags::empty(),
271            _decode,
272        )
273    }
274}
275
276pub struct ControlEventStream {
277    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
278}
279
280impl std::marker::Unpin for ControlEventStream {}
281
282impl futures::stream::FusedStream for ControlEventStream {
283    fn is_terminated(&self) -> bool {
284        self.event_receiver.is_terminated()
285    }
286}
287
288impl futures::Stream for ControlEventStream {
289    type Item = Result<ControlEvent, fidl::Error>;
290
291    fn poll_next(
292        mut self: std::pin::Pin<&mut Self>,
293        cx: &mut std::task::Context<'_>,
294    ) -> std::task::Poll<Option<Self::Item>> {
295        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
296            &mut self.event_receiver,
297            cx
298        )?) {
299            Some(buf) => std::task::Poll::Ready(Some(ControlEvent::decode(buf))),
300            None => std::task::Poll::Ready(None),
301        }
302    }
303}
304
305#[derive(Debug)]
306pub enum ControlEvent {}
307
308impl ControlEvent {
309    /// Decodes a message buffer as a [`ControlEvent`].
310    fn decode(
311        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
312    ) -> Result<ControlEvent, fidl::Error> {
313        let (bytes, _handles) = buf.split_mut();
314        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
315        debug_assert_eq!(tx_header.tx_id, 0);
316        match tx_header.ordinal {
317            _ => Err(fidl::Error::UnknownOrdinal {
318                ordinal: tx_header.ordinal,
319                protocol_name: <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
320            }),
321        }
322    }
323}
324
325/// A Stream of incoming requests for fuchsia.net.sockets/Control.
326pub struct ControlRequestStream {
327    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
328    is_terminated: bool,
329}
330
331impl std::marker::Unpin for ControlRequestStream {}
332
333impl futures::stream::FusedStream for ControlRequestStream {
334    fn is_terminated(&self) -> bool {
335        self.is_terminated
336    }
337}
338
339impl fidl::endpoints::RequestStream for ControlRequestStream {
340    type Protocol = ControlMarker;
341    type ControlHandle = ControlControlHandle;
342
343    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
344        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
345    }
346
347    fn control_handle(&self) -> Self::ControlHandle {
348        ControlControlHandle { inner: self.inner.clone() }
349    }
350
351    fn into_inner(
352        self,
353    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
354    {
355        (self.inner, self.is_terminated)
356    }
357
358    fn from_inner(
359        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
360        is_terminated: bool,
361    ) -> Self {
362        Self { inner, is_terminated }
363    }
364}
365
366impl futures::Stream for ControlRequestStream {
367    type Item = Result<ControlRequest, fidl::Error>;
368
369    fn poll_next(
370        mut self: std::pin::Pin<&mut Self>,
371        cx: &mut std::task::Context<'_>,
372    ) -> std::task::Poll<Option<Self::Item>> {
373        let this = &mut *self;
374        if this.inner.check_shutdown(cx) {
375            this.is_terminated = true;
376            return std::task::Poll::Ready(None);
377        }
378        if this.is_terminated {
379            panic!("polled ControlRequestStream after completion");
380        }
381        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
382            |bytes, handles| {
383                match this.inner.channel().read_etc(cx, bytes, handles) {
384                    std::task::Poll::Ready(Ok(())) => {}
385                    std::task::Poll::Pending => return std::task::Poll::Pending,
386                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
387                        this.is_terminated = true;
388                        return std::task::Poll::Ready(None);
389                    }
390                    std::task::Poll::Ready(Err(e)) => {
391                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
392                            e.into(),
393                        ))));
394                    }
395                }
396
397                // A message has been received from the channel
398                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
399
400                std::task::Poll::Ready(Some(match header.ordinal {
401                    0xbdaa66fbb4241a4 => {
402                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
403                        let mut req = fidl::new_empty!(
404                            ControlDisconnectIpRequest,
405                            fidl::encoding::DefaultFuchsiaResourceDialect
406                        );
407                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<ControlDisconnectIpRequest>(&header, _body_bytes, handles, &mut req)?;
408                        let control_handle = ControlControlHandle { inner: this.inner.clone() };
409                        Ok(ControlRequest::DisconnectIp {
410                            payload: req,
411                            responder: ControlDisconnectIpResponder {
412                                control_handle: std::mem::ManuallyDrop::new(control_handle),
413                                tx_id: header.tx_id,
414                            },
415                        })
416                    }
417                    _ => Err(fidl::Error::UnknownOrdinal {
418                        ordinal: header.ordinal,
419                        protocol_name:
420                            <ControlMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
421                    }),
422                }))
423            },
424        )
425    }
426}
427
428/// Provides control operations on sockets.
429#[derive(Debug)]
430pub enum ControlRequest {
431    /// Disconnect the socket matched by the provided matchers. See
432    /// `Diagnostics.IterateIp` for matcher semantics.
433    ///
434    /// Disconnecting a socket depends on the transport protocol. In all cases,
435    /// all further operations on the socket will return `ECONNABORTED`:
436    ///
437    /// - UDP: the behavior is equivalent to calling
438    ///   `fuchsia.posix.socket/*.Disconnect`. Any destination port and address,
439    ///   and bound device are removed.
440    /// - TCP LISTEN state: TCP moves to state CLOSE. All non-accepted sockets
441    ///   are closed and an RST is sent to the peer.
442    /// - TCP all other states: The TCP connection is put in state CLOSE and an
443    ///   RST is sent to the remote peer, if required.
444    ///
445    /// If no filters are specified, or the provided filters match all sockets,
446    /// an error is returned and no action is taken.
447    DisconnectIp { payload: ControlDisconnectIpRequest, responder: ControlDisconnectIpResponder },
448}
449
450impl ControlRequest {
451    #[allow(irrefutable_let_patterns)]
452    pub fn into_disconnect_ip(
453        self,
454    ) -> Option<(ControlDisconnectIpRequest, ControlDisconnectIpResponder)> {
455        if let ControlRequest::DisconnectIp { payload, responder } = self {
456            Some((payload, responder))
457        } else {
458            None
459        }
460    }
461
462    /// Name of the method defined in FIDL
463    pub fn method_name(&self) -> &'static str {
464        match *self {
465            ControlRequest::DisconnectIp { .. } => "disconnect_ip",
466        }
467    }
468}
469
470#[derive(Debug, Clone)]
471pub struct ControlControlHandle {
472    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
473}
474
475impl fidl::endpoints::ControlHandle for ControlControlHandle {
476    fn shutdown(&self) {
477        self.inner.shutdown()
478    }
479    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
480        self.inner.shutdown_with_epitaph(status)
481    }
482
483    fn is_closed(&self) -> bool {
484        self.inner.channel().is_closed()
485    }
486    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
487        self.inner.channel().on_closed()
488    }
489
490    #[cfg(target_os = "fuchsia")]
491    fn signal_peer(
492        &self,
493        clear_mask: zx::Signals,
494        set_mask: zx::Signals,
495    ) -> Result<(), zx_status::Status> {
496        use fidl::Peered;
497        self.inner.channel().signal_peer(clear_mask, set_mask)
498    }
499}
500
501impl ControlControlHandle {}
502
503#[must_use = "FIDL methods require a response to be sent"]
504#[derive(Debug)]
505pub struct ControlDisconnectIpResponder {
506    control_handle: std::mem::ManuallyDrop<ControlControlHandle>,
507    tx_id: u32,
508}
509
510/// Set the the channel to be shutdown (see [`ControlControlHandle::shutdown`])
511/// if the responder is dropped without sending a response, so that the client
512/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
513impl std::ops::Drop for ControlDisconnectIpResponder {
514    fn drop(&mut self) {
515        self.control_handle.shutdown();
516        // Safety: drops once, never accessed again
517        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
518    }
519}
520
521impl fidl::endpoints::Responder for ControlDisconnectIpResponder {
522    type ControlHandle = ControlControlHandle;
523
524    fn control_handle(&self) -> &ControlControlHandle {
525        &self.control_handle
526    }
527
528    fn drop_without_shutdown(mut self) {
529        // Safety: drops once, never accessed again due to mem::forget
530        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
531        // Prevent Drop from running (which would shut down the channel)
532        std::mem::forget(self);
533    }
534}
535
536impl ControlDisconnectIpResponder {
537    /// Sends a response to the FIDL transaction.
538    ///
539    /// Sets the channel to shutdown if an error occurs.
540    pub fn send(
541        self,
542        mut result: Result<u32, ControlDisconnectIpError>,
543    ) -> Result<(), fidl::Error> {
544        let _result = self.send_raw(result);
545        if _result.is_err() {
546            self.control_handle.shutdown();
547        }
548        self.drop_without_shutdown();
549        _result
550    }
551
552    /// Similar to "send" but does not shutdown the channel if an error occurs.
553    pub fn send_no_shutdown_on_err(
554        self,
555        mut result: Result<u32, ControlDisconnectIpError>,
556    ) -> Result<(), fidl::Error> {
557        let _result = self.send_raw(result);
558        self.drop_without_shutdown();
559        _result
560    }
561
562    fn send_raw(
563        &self,
564        mut result: Result<u32, ControlDisconnectIpError>,
565    ) -> Result<(), fidl::Error> {
566        self.control_handle.inner.send::<fidl::encoding::ResultType<
567            ControlDisconnectIpResponse,
568            ControlDisconnectIpError,
569        >>(
570            result.map(|disconnected| (disconnected,)),
571            self.tx_id,
572            0xbdaa66fbb4241a4,
573            fidl::encoding::DynamicFlags::empty(),
574        )
575    }
576}
577
578#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
579pub struct DiagnosticsMarker;
580
581impl fidl::endpoints::ProtocolMarker for DiagnosticsMarker {
582    type Proxy = DiagnosticsProxy;
583    type RequestStream = DiagnosticsRequestStream;
584    #[cfg(target_os = "fuchsia")]
585    type SynchronousProxy = DiagnosticsSynchronousProxy;
586
587    const DEBUG_NAME: &'static str = "fuchsia.net.sockets.Diagnostics";
588}
589impl fidl::endpoints::DiscoverableProtocolMarker for DiagnosticsMarker {}
590pub type DiagnosticsIterateIpResult = Result<(), DiagnosticsIterateIpError>;
591
592pub trait DiagnosticsProxyInterface: Send + Sync {
593    type IterateIpResponseFut: std::future::Future<Output = Result<DiagnosticsIterateIpResult, fidl::Error>>
594        + Send;
595    fn r#iterate_ip(
596        &self,
597        s: fidl::endpoints::ServerEnd<IpIteratorMarker>,
598        extensions: Extensions,
599        matchers: &[IpSocketMatcher],
600    ) -> Self::IterateIpResponseFut;
601}
602#[derive(Debug)]
603#[cfg(target_os = "fuchsia")]
604pub struct DiagnosticsSynchronousProxy {
605    client: fidl::client::sync::Client,
606}
607
608#[cfg(target_os = "fuchsia")]
609impl fidl::endpoints::SynchronousProxy for DiagnosticsSynchronousProxy {
610    type Proxy = DiagnosticsProxy;
611    type Protocol = DiagnosticsMarker;
612
613    fn from_channel(inner: fidl::Channel) -> Self {
614        Self::new(inner)
615    }
616
617    fn into_channel(self) -> fidl::Channel {
618        self.client.into_channel()
619    }
620
621    fn as_channel(&self) -> &fidl::Channel {
622        self.client.as_channel()
623    }
624}
625
626#[cfg(target_os = "fuchsia")]
627impl DiagnosticsSynchronousProxy {
628    pub fn new(channel: fidl::Channel) -> Self {
629        let protocol_name = <DiagnosticsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
630        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
631    }
632
633    pub fn into_channel(self) -> fidl::Channel {
634        self.client.into_channel()
635    }
636
637    /// Waits until an event arrives and returns it. It is safe for other
638    /// threads to make concurrent requests while waiting for an event.
639    pub fn wait_for_event(
640        &self,
641        deadline: zx::MonotonicInstant,
642    ) -> Result<DiagnosticsEvent, fidl::Error> {
643        DiagnosticsEvent::decode(self.client.wait_for_event(deadline)?)
644    }
645
646    /// Populates an iterator over all IP sockets that match the provided
647    /// filters.
648    ///
649    /// Unbound sockets are not returned.
650    pub fn r#iterate_ip(
651        &self,
652        mut s: fidl::endpoints::ServerEnd<IpIteratorMarker>,
653        mut extensions: Extensions,
654        mut matchers: &[IpSocketMatcher],
655        ___deadline: zx::MonotonicInstant,
656    ) -> Result<DiagnosticsIterateIpResult, fidl::Error> {
657        let _response =
658            self.client.send_query::<DiagnosticsIterateIpRequest, fidl::encoding::ResultType<
659                fidl::encoding::EmptyStruct,
660                DiagnosticsIterateIpError,
661            >>(
662                (s, extensions, matchers),
663                0x7b05425e48d07605,
664                fidl::encoding::DynamicFlags::empty(),
665                ___deadline,
666            )?;
667        Ok(_response.map(|x| x))
668    }
669}
670
671#[cfg(target_os = "fuchsia")]
672impl From<DiagnosticsSynchronousProxy> for zx::Handle {
673    fn from(value: DiagnosticsSynchronousProxy) -> Self {
674        value.into_channel().into()
675    }
676}
677
678#[cfg(target_os = "fuchsia")]
679impl From<fidl::Channel> for DiagnosticsSynchronousProxy {
680    fn from(value: fidl::Channel) -> Self {
681        Self::new(value)
682    }
683}
684
685#[cfg(target_os = "fuchsia")]
686impl fidl::endpoints::FromClient for DiagnosticsSynchronousProxy {
687    type Protocol = DiagnosticsMarker;
688
689    fn from_client(value: fidl::endpoints::ClientEnd<DiagnosticsMarker>) -> Self {
690        Self::new(value.into_channel())
691    }
692}
693
694#[derive(Debug, Clone)]
695pub struct DiagnosticsProxy {
696    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
697}
698
699impl fidl::endpoints::Proxy for DiagnosticsProxy {
700    type Protocol = DiagnosticsMarker;
701
702    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
703        Self::new(inner)
704    }
705
706    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
707        self.client.into_channel().map_err(|client| Self { client })
708    }
709
710    fn as_channel(&self) -> &::fidl::AsyncChannel {
711        self.client.as_channel()
712    }
713}
714
715impl DiagnosticsProxy {
716    /// Create a new Proxy for fuchsia.net.sockets/Diagnostics.
717    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
718        let protocol_name = <DiagnosticsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
719        Self { client: fidl::client::Client::new(channel, protocol_name) }
720    }
721
722    /// Get a Stream of events from the remote end of the protocol.
723    ///
724    /// # Panics
725    ///
726    /// Panics if the event stream was already taken.
727    pub fn take_event_stream(&self) -> DiagnosticsEventStream {
728        DiagnosticsEventStream { event_receiver: self.client.take_event_receiver() }
729    }
730
731    /// Populates an iterator over all IP sockets that match the provided
732    /// filters.
733    ///
734    /// Unbound sockets are not returned.
735    pub fn r#iterate_ip(
736        &self,
737        mut s: fidl::endpoints::ServerEnd<IpIteratorMarker>,
738        mut extensions: Extensions,
739        mut matchers: &[IpSocketMatcher],
740    ) -> fidl::client::QueryResponseFut<
741        DiagnosticsIterateIpResult,
742        fidl::encoding::DefaultFuchsiaResourceDialect,
743    > {
744        DiagnosticsProxyInterface::r#iterate_ip(self, s, extensions, matchers)
745    }
746}
747
748impl DiagnosticsProxyInterface for DiagnosticsProxy {
749    type IterateIpResponseFut = fidl::client::QueryResponseFut<
750        DiagnosticsIterateIpResult,
751        fidl::encoding::DefaultFuchsiaResourceDialect,
752    >;
753    fn r#iterate_ip(
754        &self,
755        mut s: fidl::endpoints::ServerEnd<IpIteratorMarker>,
756        mut extensions: Extensions,
757        mut matchers: &[IpSocketMatcher],
758    ) -> Self::IterateIpResponseFut {
759        fn _decode(
760            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
761        ) -> Result<DiagnosticsIterateIpResult, fidl::Error> {
762            let _response = fidl::client::decode_transaction_body::<
763                fidl::encoding::ResultType<fidl::encoding::EmptyStruct, DiagnosticsIterateIpError>,
764                fidl::encoding::DefaultFuchsiaResourceDialect,
765                0x7b05425e48d07605,
766            >(_buf?)?;
767            Ok(_response.map(|x| x))
768        }
769        self.client
770            .send_query_and_decode::<DiagnosticsIterateIpRequest, DiagnosticsIterateIpResult>(
771                (s, extensions, matchers),
772                0x7b05425e48d07605,
773                fidl::encoding::DynamicFlags::empty(),
774                _decode,
775            )
776    }
777}
778
779pub struct DiagnosticsEventStream {
780    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
781}
782
783impl std::marker::Unpin for DiagnosticsEventStream {}
784
785impl futures::stream::FusedStream for DiagnosticsEventStream {
786    fn is_terminated(&self) -> bool {
787        self.event_receiver.is_terminated()
788    }
789}
790
791impl futures::Stream for DiagnosticsEventStream {
792    type Item = Result<DiagnosticsEvent, fidl::Error>;
793
794    fn poll_next(
795        mut self: std::pin::Pin<&mut Self>,
796        cx: &mut std::task::Context<'_>,
797    ) -> std::task::Poll<Option<Self::Item>> {
798        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
799            &mut self.event_receiver,
800            cx
801        )?) {
802            Some(buf) => std::task::Poll::Ready(Some(DiagnosticsEvent::decode(buf))),
803            None => std::task::Poll::Ready(None),
804        }
805    }
806}
807
808#[derive(Debug)]
809pub enum DiagnosticsEvent {}
810
811impl DiagnosticsEvent {
812    /// Decodes a message buffer as a [`DiagnosticsEvent`].
813    fn decode(
814        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
815    ) -> Result<DiagnosticsEvent, fidl::Error> {
816        let (bytes, _handles) = buf.split_mut();
817        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
818        debug_assert_eq!(tx_header.tx_id, 0);
819        match tx_header.ordinal {
820            _ => Err(fidl::Error::UnknownOrdinal {
821                ordinal: tx_header.ordinal,
822                protocol_name: <DiagnosticsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
823            }),
824        }
825    }
826}
827
828/// A Stream of incoming requests for fuchsia.net.sockets/Diagnostics.
829pub struct DiagnosticsRequestStream {
830    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
831    is_terminated: bool,
832}
833
834impl std::marker::Unpin for DiagnosticsRequestStream {}
835
836impl futures::stream::FusedStream for DiagnosticsRequestStream {
837    fn is_terminated(&self) -> bool {
838        self.is_terminated
839    }
840}
841
842impl fidl::endpoints::RequestStream for DiagnosticsRequestStream {
843    type Protocol = DiagnosticsMarker;
844    type ControlHandle = DiagnosticsControlHandle;
845
846    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
847        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
848    }
849
850    fn control_handle(&self) -> Self::ControlHandle {
851        DiagnosticsControlHandle { inner: self.inner.clone() }
852    }
853
854    fn into_inner(
855        self,
856    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
857    {
858        (self.inner, self.is_terminated)
859    }
860
861    fn from_inner(
862        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
863        is_terminated: bool,
864    ) -> Self {
865        Self { inner, is_terminated }
866    }
867}
868
869impl futures::Stream for DiagnosticsRequestStream {
870    type Item = Result<DiagnosticsRequest, fidl::Error>;
871
872    fn poll_next(
873        mut self: std::pin::Pin<&mut Self>,
874        cx: &mut std::task::Context<'_>,
875    ) -> std::task::Poll<Option<Self::Item>> {
876        let this = &mut *self;
877        if this.inner.check_shutdown(cx) {
878            this.is_terminated = true;
879            return std::task::Poll::Ready(None);
880        }
881        if this.is_terminated {
882            panic!("polled DiagnosticsRequestStream after completion");
883        }
884        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
885            |bytes, handles| {
886                match this.inner.channel().read_etc(cx, bytes, handles) {
887                    std::task::Poll::Ready(Ok(())) => {}
888                    std::task::Poll::Pending => return std::task::Poll::Pending,
889                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
890                        this.is_terminated = true;
891                        return std::task::Poll::Ready(None);
892                    }
893                    std::task::Poll::Ready(Err(e)) => {
894                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
895                            e.into(),
896                        ))));
897                    }
898                }
899
900                // A message has been received from the channel
901                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
902
903                std::task::Poll::Ready(Some(match header.ordinal {
904                    0x7b05425e48d07605 => {
905                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
906                        let mut req = fidl::new_empty!(
907                            DiagnosticsIterateIpRequest,
908                            fidl::encoding::DefaultFuchsiaResourceDialect
909                        );
910                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<DiagnosticsIterateIpRequest>(&header, _body_bytes, handles, &mut req)?;
911                        let control_handle = DiagnosticsControlHandle { inner: this.inner.clone() };
912                        Ok(DiagnosticsRequest::IterateIp {
913                            s: req.s,
914                            extensions: req.extensions,
915                            matchers: req.matchers,
916
917                            responder: DiagnosticsIterateIpResponder {
918                                control_handle: std::mem::ManuallyDrop::new(control_handle),
919                                tx_id: header.tx_id,
920                            },
921                        })
922                    }
923                    _ => Err(fidl::Error::UnknownOrdinal {
924                        ordinal: header.ordinal,
925                        protocol_name:
926                            <DiagnosticsMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
927                    }),
928                }))
929            },
930        )
931    }
932}
933
934/// Provides diagnostic information IP sockets.
935#[derive(Debug)]
936pub enum DiagnosticsRequest {
937    /// Populates an iterator over all IP sockets that match the provided
938    /// filters.
939    ///
940    /// Unbound sockets are not returned.
941    IterateIp {
942        s: fidl::endpoints::ServerEnd<IpIteratorMarker>,
943        extensions: Extensions,
944        matchers: Vec<IpSocketMatcher>,
945        responder: DiagnosticsIterateIpResponder,
946    },
947}
948
949impl DiagnosticsRequest {
950    #[allow(irrefutable_let_patterns)]
951    pub fn into_iterate_ip(
952        self,
953    ) -> Option<(
954        fidl::endpoints::ServerEnd<IpIteratorMarker>,
955        Extensions,
956        Vec<IpSocketMatcher>,
957        DiagnosticsIterateIpResponder,
958    )> {
959        if let DiagnosticsRequest::IterateIp { s, extensions, matchers, responder } = self {
960            Some((s, extensions, matchers, responder))
961        } else {
962            None
963        }
964    }
965
966    /// Name of the method defined in FIDL
967    pub fn method_name(&self) -> &'static str {
968        match *self {
969            DiagnosticsRequest::IterateIp { .. } => "iterate_ip",
970        }
971    }
972}
973
974#[derive(Debug, Clone)]
975pub struct DiagnosticsControlHandle {
976    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
977}
978
979impl fidl::endpoints::ControlHandle for DiagnosticsControlHandle {
980    fn shutdown(&self) {
981        self.inner.shutdown()
982    }
983    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
984        self.inner.shutdown_with_epitaph(status)
985    }
986
987    fn is_closed(&self) -> bool {
988        self.inner.channel().is_closed()
989    }
990    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
991        self.inner.channel().on_closed()
992    }
993
994    #[cfg(target_os = "fuchsia")]
995    fn signal_peer(
996        &self,
997        clear_mask: zx::Signals,
998        set_mask: zx::Signals,
999    ) -> Result<(), zx_status::Status> {
1000        use fidl::Peered;
1001        self.inner.channel().signal_peer(clear_mask, set_mask)
1002    }
1003}
1004
1005impl DiagnosticsControlHandle {}
1006
1007#[must_use = "FIDL methods require a response to be sent"]
1008#[derive(Debug)]
1009pub struct DiagnosticsIterateIpResponder {
1010    control_handle: std::mem::ManuallyDrop<DiagnosticsControlHandle>,
1011    tx_id: u32,
1012}
1013
1014/// Set the the channel to be shutdown (see [`DiagnosticsControlHandle::shutdown`])
1015/// if the responder is dropped without sending a response, so that the client
1016/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1017impl std::ops::Drop for DiagnosticsIterateIpResponder {
1018    fn drop(&mut self) {
1019        self.control_handle.shutdown();
1020        // Safety: drops once, never accessed again
1021        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1022    }
1023}
1024
1025impl fidl::endpoints::Responder for DiagnosticsIterateIpResponder {
1026    type ControlHandle = DiagnosticsControlHandle;
1027
1028    fn control_handle(&self) -> &DiagnosticsControlHandle {
1029        &self.control_handle
1030    }
1031
1032    fn drop_without_shutdown(mut self) {
1033        // Safety: drops once, never accessed again due to mem::forget
1034        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1035        // Prevent Drop from running (which would shut down the channel)
1036        std::mem::forget(self);
1037    }
1038}
1039
1040impl DiagnosticsIterateIpResponder {
1041    /// Sends a response to the FIDL transaction.
1042    ///
1043    /// Sets the channel to shutdown if an error occurs.
1044    pub fn send(
1045        self,
1046        mut result: Result<(), DiagnosticsIterateIpError>,
1047    ) -> Result<(), fidl::Error> {
1048        let _result = self.send_raw(result);
1049        if _result.is_err() {
1050            self.control_handle.shutdown();
1051        }
1052        self.drop_without_shutdown();
1053        _result
1054    }
1055
1056    /// Similar to "send" but does not shutdown the channel if an error occurs.
1057    pub fn send_no_shutdown_on_err(
1058        self,
1059        mut result: Result<(), DiagnosticsIterateIpError>,
1060    ) -> Result<(), fidl::Error> {
1061        let _result = self.send_raw(result);
1062        self.drop_without_shutdown();
1063        _result
1064    }
1065
1066    fn send_raw(
1067        &self,
1068        mut result: Result<(), DiagnosticsIterateIpError>,
1069    ) -> Result<(), fidl::Error> {
1070        self.control_handle.inner.send::<fidl::encoding::ResultType<
1071            fidl::encoding::EmptyStruct,
1072            DiagnosticsIterateIpError,
1073        >>(
1074            result,
1075            self.tx_id,
1076            0x7b05425e48d07605,
1077            fidl::encoding::DynamicFlags::empty(),
1078        )
1079    }
1080}
1081
1082#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1083pub struct IpIteratorMarker;
1084
1085impl fidl::endpoints::ProtocolMarker for IpIteratorMarker {
1086    type Proxy = IpIteratorProxy;
1087    type RequestStream = IpIteratorRequestStream;
1088    #[cfg(target_os = "fuchsia")]
1089    type SynchronousProxy = IpIteratorSynchronousProxy;
1090
1091    const DEBUG_NAME: &'static str = "(anonymous) IpIterator";
1092}
1093
1094pub trait IpIteratorProxyInterface: Send + Sync {
1095    type NextResponseFut: std::future::Future<Output = Result<(Vec<IpSocketState>, bool), fidl::Error>>
1096        + Send;
1097    fn r#next(&self) -> Self::NextResponseFut;
1098}
1099#[derive(Debug)]
1100#[cfg(target_os = "fuchsia")]
1101pub struct IpIteratorSynchronousProxy {
1102    client: fidl::client::sync::Client,
1103}
1104
1105#[cfg(target_os = "fuchsia")]
1106impl fidl::endpoints::SynchronousProxy for IpIteratorSynchronousProxy {
1107    type Proxy = IpIteratorProxy;
1108    type Protocol = IpIteratorMarker;
1109
1110    fn from_channel(inner: fidl::Channel) -> Self {
1111        Self::new(inner)
1112    }
1113
1114    fn into_channel(self) -> fidl::Channel {
1115        self.client.into_channel()
1116    }
1117
1118    fn as_channel(&self) -> &fidl::Channel {
1119        self.client.as_channel()
1120    }
1121}
1122
1123#[cfg(target_os = "fuchsia")]
1124impl IpIteratorSynchronousProxy {
1125    pub fn new(channel: fidl::Channel) -> Self {
1126        let protocol_name = <IpIteratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1127        Self { client: fidl::client::sync::Client::new(channel, protocol_name) }
1128    }
1129
1130    pub fn into_channel(self) -> fidl::Channel {
1131        self.client.into_channel()
1132    }
1133
1134    /// Waits until an event arrives and returns it. It is safe for other
1135    /// threads to make concurrent requests while waiting for an event.
1136    pub fn wait_for_event(
1137        &self,
1138        deadline: zx::MonotonicInstant,
1139    ) -> Result<IpIteratorEvent, fidl::Error> {
1140        IpIteratorEvent::decode(self.client.wait_for_event(deadline)?)
1141    }
1142
1143    /// Call repeatedly to stream results for a previous request to
1144    /// `Diagnostics.IterateIp`.
1145    ///
1146    /// A caller must make sure to retrieve sockets in a timely manner, or the
1147    /// connection may be closed with `TIMED_OUT`.
1148    ///
1149    /// NOTE: The returned sockets do not provide a consistent snapshot of the
1150    /// system. For example, you should never use the state of one socket to
1151    /// infer what the state of another socket will be, since modifications
1152    /// could have occurred in between results for each socket being
1153    /// materialized.
1154    pub fn r#next(
1155        &self,
1156        ___deadline: zx::MonotonicInstant,
1157    ) -> Result<(Vec<IpSocketState>, bool), fidl::Error> {
1158        let _response =
1159            self.client.send_query::<fidl::encoding::EmptyPayload, IpIteratorNextResponse>(
1160                (),
1161                0x3d50aa08ce641a6b,
1162                fidl::encoding::DynamicFlags::empty(),
1163                ___deadline,
1164            )?;
1165        Ok((_response.sockets, _response.has_more))
1166    }
1167}
1168
1169#[cfg(target_os = "fuchsia")]
1170impl From<IpIteratorSynchronousProxy> for zx::Handle {
1171    fn from(value: IpIteratorSynchronousProxy) -> Self {
1172        value.into_channel().into()
1173    }
1174}
1175
1176#[cfg(target_os = "fuchsia")]
1177impl From<fidl::Channel> for IpIteratorSynchronousProxy {
1178    fn from(value: fidl::Channel) -> Self {
1179        Self::new(value)
1180    }
1181}
1182
1183#[cfg(target_os = "fuchsia")]
1184impl fidl::endpoints::FromClient for IpIteratorSynchronousProxy {
1185    type Protocol = IpIteratorMarker;
1186
1187    fn from_client(value: fidl::endpoints::ClientEnd<IpIteratorMarker>) -> Self {
1188        Self::new(value.into_channel())
1189    }
1190}
1191
1192#[derive(Debug, Clone)]
1193pub struct IpIteratorProxy {
1194    client: fidl::client::Client<fidl::encoding::DefaultFuchsiaResourceDialect>,
1195}
1196
1197impl fidl::endpoints::Proxy for IpIteratorProxy {
1198    type Protocol = IpIteratorMarker;
1199
1200    fn from_channel(inner: ::fidl::AsyncChannel) -> Self {
1201        Self::new(inner)
1202    }
1203
1204    fn into_channel(self) -> Result<::fidl::AsyncChannel, Self> {
1205        self.client.into_channel().map_err(|client| Self { client })
1206    }
1207
1208    fn as_channel(&self) -> &::fidl::AsyncChannel {
1209        self.client.as_channel()
1210    }
1211}
1212
1213impl IpIteratorProxy {
1214    /// Create a new Proxy for fuchsia.net.sockets/IpIterator.
1215    pub fn new(channel: ::fidl::AsyncChannel) -> Self {
1216        let protocol_name = <IpIteratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME;
1217        Self { client: fidl::client::Client::new(channel, protocol_name) }
1218    }
1219
1220    /// Get a Stream of events from the remote end of the protocol.
1221    ///
1222    /// # Panics
1223    ///
1224    /// Panics if the event stream was already taken.
1225    pub fn take_event_stream(&self) -> IpIteratorEventStream {
1226        IpIteratorEventStream { event_receiver: self.client.take_event_receiver() }
1227    }
1228
1229    /// Call repeatedly to stream results for a previous request to
1230    /// `Diagnostics.IterateIp`.
1231    ///
1232    /// A caller must make sure to retrieve sockets in a timely manner, or the
1233    /// connection may be closed with `TIMED_OUT`.
1234    ///
1235    /// NOTE: The returned sockets do not provide a consistent snapshot of the
1236    /// system. For example, you should never use the state of one socket to
1237    /// infer what the state of another socket will be, since modifications
1238    /// could have occurred in between results for each socket being
1239    /// materialized.
1240    pub fn r#next(
1241        &self,
1242    ) -> fidl::client::QueryResponseFut<
1243        (Vec<IpSocketState>, bool),
1244        fidl::encoding::DefaultFuchsiaResourceDialect,
1245    > {
1246        IpIteratorProxyInterface::r#next(self)
1247    }
1248}
1249
1250impl IpIteratorProxyInterface for IpIteratorProxy {
1251    type NextResponseFut = fidl::client::QueryResponseFut<
1252        (Vec<IpSocketState>, bool),
1253        fidl::encoding::DefaultFuchsiaResourceDialect,
1254    >;
1255    fn r#next(&self) -> Self::NextResponseFut {
1256        fn _decode(
1257            mut _buf: Result<<fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc, fidl::Error>,
1258        ) -> Result<(Vec<IpSocketState>, bool), fidl::Error> {
1259            let _response = fidl::client::decode_transaction_body::<
1260                IpIteratorNextResponse,
1261                fidl::encoding::DefaultFuchsiaResourceDialect,
1262                0x3d50aa08ce641a6b,
1263            >(_buf?)?;
1264            Ok((_response.sockets, _response.has_more))
1265        }
1266        self.client
1267            .send_query_and_decode::<fidl::encoding::EmptyPayload, (Vec<IpSocketState>, bool)>(
1268                (),
1269                0x3d50aa08ce641a6b,
1270                fidl::encoding::DynamicFlags::empty(),
1271                _decode,
1272            )
1273    }
1274}
1275
1276pub struct IpIteratorEventStream {
1277    event_receiver: fidl::client::EventReceiver<fidl::encoding::DefaultFuchsiaResourceDialect>,
1278}
1279
1280impl std::marker::Unpin for IpIteratorEventStream {}
1281
1282impl futures::stream::FusedStream for IpIteratorEventStream {
1283    fn is_terminated(&self) -> bool {
1284        self.event_receiver.is_terminated()
1285    }
1286}
1287
1288impl futures::Stream for IpIteratorEventStream {
1289    type Item = Result<IpIteratorEvent, fidl::Error>;
1290
1291    fn poll_next(
1292        mut self: std::pin::Pin<&mut Self>,
1293        cx: &mut std::task::Context<'_>,
1294    ) -> std::task::Poll<Option<Self::Item>> {
1295        match futures::ready!(futures::stream::StreamExt::poll_next_unpin(
1296            &mut self.event_receiver,
1297            cx
1298        )?) {
1299            Some(buf) => std::task::Poll::Ready(Some(IpIteratorEvent::decode(buf))),
1300            None => std::task::Poll::Ready(None),
1301        }
1302    }
1303}
1304
1305#[derive(Debug)]
1306pub enum IpIteratorEvent {
1307    #[non_exhaustive]
1308    _UnknownEvent {
1309        /// Ordinal of the event that was sent.
1310        ordinal: u64,
1311    },
1312}
1313
1314impl IpIteratorEvent {
1315    /// Decodes a message buffer as a [`IpIteratorEvent`].
1316    fn decode(
1317        mut buf: <fidl::encoding::DefaultFuchsiaResourceDialect as fidl::encoding::ResourceDialect>::MessageBufEtc,
1318    ) -> Result<IpIteratorEvent, fidl::Error> {
1319        let (bytes, _handles) = buf.split_mut();
1320        let (tx_header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1321        debug_assert_eq!(tx_header.tx_id, 0);
1322        match tx_header.ordinal {
1323            _ if tx_header.dynamic_flags().contains(fidl::encoding::DynamicFlags::FLEXIBLE) => {
1324                Ok(IpIteratorEvent::_UnknownEvent { ordinal: tx_header.ordinal })
1325            }
1326            _ => Err(fidl::Error::UnknownOrdinal {
1327                ordinal: tx_header.ordinal,
1328                protocol_name: <IpIteratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1329            }),
1330        }
1331    }
1332}
1333
1334/// A Stream of incoming requests for fuchsia.net.sockets/IpIterator.
1335pub struct IpIteratorRequestStream {
1336    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1337    is_terminated: bool,
1338}
1339
1340impl std::marker::Unpin for IpIteratorRequestStream {}
1341
1342impl futures::stream::FusedStream for IpIteratorRequestStream {
1343    fn is_terminated(&self) -> bool {
1344        self.is_terminated
1345    }
1346}
1347
1348impl fidl::endpoints::RequestStream for IpIteratorRequestStream {
1349    type Protocol = IpIteratorMarker;
1350    type ControlHandle = IpIteratorControlHandle;
1351
1352    fn from_channel(channel: ::fidl::AsyncChannel) -> Self {
1353        Self { inner: std::sync::Arc::new(fidl::ServeInner::new(channel)), is_terminated: false }
1354    }
1355
1356    fn control_handle(&self) -> Self::ControlHandle {
1357        IpIteratorControlHandle { inner: self.inner.clone() }
1358    }
1359
1360    fn into_inner(
1361        self,
1362    ) -> (::std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>, bool)
1363    {
1364        (self.inner, self.is_terminated)
1365    }
1366
1367    fn from_inner(
1368        inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1369        is_terminated: bool,
1370    ) -> Self {
1371        Self { inner, is_terminated }
1372    }
1373}
1374
1375impl futures::Stream for IpIteratorRequestStream {
1376    type Item = Result<IpIteratorRequest, fidl::Error>;
1377
1378    fn poll_next(
1379        mut self: std::pin::Pin<&mut Self>,
1380        cx: &mut std::task::Context<'_>,
1381    ) -> std::task::Poll<Option<Self::Item>> {
1382        let this = &mut *self;
1383        if this.inner.check_shutdown(cx) {
1384            this.is_terminated = true;
1385            return std::task::Poll::Ready(None);
1386        }
1387        if this.is_terminated {
1388            panic!("polled IpIteratorRequestStream after completion");
1389        }
1390        fidl::encoding::with_tls_decode_buf::<_, fidl::encoding::DefaultFuchsiaResourceDialect>(
1391            |bytes, handles| {
1392                match this.inner.channel().read_etc(cx, bytes, handles) {
1393                    std::task::Poll::Ready(Ok(())) => {}
1394                    std::task::Poll::Pending => return std::task::Poll::Pending,
1395                    std::task::Poll::Ready(Err(zx_status::Status::PEER_CLOSED)) => {
1396                        this.is_terminated = true;
1397                        return std::task::Poll::Ready(None);
1398                    }
1399                    std::task::Poll::Ready(Err(e)) => {
1400                        return std::task::Poll::Ready(Some(Err(fidl::Error::ServerRequestRead(
1401                            e.into(),
1402                        ))));
1403                    }
1404                }
1405
1406                // A message has been received from the channel
1407                let (header, _body_bytes) = fidl::encoding::decode_transaction_header(bytes)?;
1408
1409                std::task::Poll::Ready(Some(match header.ordinal {
1410                    0x3d50aa08ce641a6b => {
1411                        header.validate_request_tx_id(fidl::MethodType::TwoWay)?;
1412                        let mut req = fidl::new_empty!(
1413                            fidl::encoding::EmptyPayload,
1414                            fidl::encoding::DefaultFuchsiaResourceDialect
1415                        );
1416                        fidl::encoding::Decoder::<fidl::encoding::DefaultFuchsiaResourceDialect>::decode_into::<fidl::encoding::EmptyPayload>(&header, _body_bytes, handles, &mut req)?;
1417                        let control_handle = IpIteratorControlHandle { inner: this.inner.clone() };
1418                        Ok(IpIteratorRequest::Next {
1419                            responder: IpIteratorNextResponder {
1420                                control_handle: std::mem::ManuallyDrop::new(control_handle),
1421                                tx_id: header.tx_id,
1422                            },
1423                        })
1424                    }
1425                    _ if header.tx_id == 0
1426                        && header
1427                            .dynamic_flags()
1428                            .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
1429                    {
1430                        Ok(IpIteratorRequest::_UnknownMethod {
1431                            ordinal: header.ordinal,
1432                            control_handle: IpIteratorControlHandle { inner: this.inner.clone() },
1433                            method_type: fidl::MethodType::OneWay,
1434                        })
1435                    }
1436                    _ if header
1437                        .dynamic_flags()
1438                        .contains(fidl::encoding::DynamicFlags::FLEXIBLE) =>
1439                    {
1440                        this.inner.send_framework_err(
1441                            fidl::encoding::FrameworkErr::UnknownMethod,
1442                            header.tx_id,
1443                            header.ordinal,
1444                            header.dynamic_flags(),
1445                            (bytes, handles),
1446                        )?;
1447                        Ok(IpIteratorRequest::_UnknownMethod {
1448                            ordinal: header.ordinal,
1449                            control_handle: IpIteratorControlHandle { inner: this.inner.clone() },
1450                            method_type: fidl::MethodType::TwoWay,
1451                        })
1452                    }
1453                    _ => Err(fidl::Error::UnknownOrdinal {
1454                        ordinal: header.ordinal,
1455                        protocol_name:
1456                            <IpIteratorMarker as fidl::endpoints::ProtocolMarker>::DEBUG_NAME,
1457                    }),
1458                }))
1459            },
1460        )
1461    }
1462}
1463
1464/// Provides sockets as a response to a call to `Diagnostics.IterateIp`.
1465#[derive(Debug)]
1466pub enum IpIteratorRequest {
1467    /// Call repeatedly to stream results for a previous request to
1468    /// `Diagnostics.IterateIp`.
1469    ///
1470    /// A caller must make sure to retrieve sockets in a timely manner, or the
1471    /// connection may be closed with `TIMED_OUT`.
1472    ///
1473    /// NOTE: The returned sockets do not provide a consistent snapshot of the
1474    /// system. For example, you should never use the state of one socket to
1475    /// infer what the state of another socket will be, since modifications
1476    /// could have occurred in between results for each socket being
1477    /// materialized.
1478    Next { responder: IpIteratorNextResponder },
1479    /// An interaction was received which does not match any known method.
1480    #[non_exhaustive]
1481    _UnknownMethod {
1482        /// Ordinal of the method that was called.
1483        ordinal: u64,
1484        control_handle: IpIteratorControlHandle,
1485        method_type: fidl::MethodType,
1486    },
1487}
1488
1489impl IpIteratorRequest {
1490    #[allow(irrefutable_let_patterns)]
1491    pub fn into_next(self) -> Option<(IpIteratorNextResponder)> {
1492        if let IpIteratorRequest::Next { responder } = self { Some((responder)) } else { None }
1493    }
1494
1495    /// Name of the method defined in FIDL
1496    pub fn method_name(&self) -> &'static str {
1497        match *self {
1498            IpIteratorRequest::Next { .. } => "next",
1499            IpIteratorRequest::_UnknownMethod { method_type: fidl::MethodType::OneWay, .. } => {
1500                "unknown one-way method"
1501            }
1502            IpIteratorRequest::_UnknownMethod { method_type: fidl::MethodType::TwoWay, .. } => {
1503                "unknown two-way method"
1504            }
1505        }
1506    }
1507}
1508
1509#[derive(Debug, Clone)]
1510pub struct IpIteratorControlHandle {
1511    inner: std::sync::Arc<fidl::ServeInner<fidl::encoding::DefaultFuchsiaResourceDialect>>,
1512}
1513
1514impl fidl::endpoints::ControlHandle for IpIteratorControlHandle {
1515    fn shutdown(&self) {
1516        self.inner.shutdown()
1517    }
1518    fn shutdown_with_epitaph(&self, status: zx_status::Status) {
1519        self.inner.shutdown_with_epitaph(status)
1520    }
1521
1522    fn is_closed(&self) -> bool {
1523        self.inner.channel().is_closed()
1524    }
1525    fn on_closed(&self) -> fidl::OnSignalsRef<'_> {
1526        self.inner.channel().on_closed()
1527    }
1528
1529    #[cfg(target_os = "fuchsia")]
1530    fn signal_peer(
1531        &self,
1532        clear_mask: zx::Signals,
1533        set_mask: zx::Signals,
1534    ) -> Result<(), zx_status::Status> {
1535        use fidl::Peered;
1536        self.inner.channel().signal_peer(clear_mask, set_mask)
1537    }
1538}
1539
1540impl IpIteratorControlHandle {}
1541
1542#[must_use = "FIDL methods require a response to be sent"]
1543#[derive(Debug)]
1544pub struct IpIteratorNextResponder {
1545    control_handle: std::mem::ManuallyDrop<IpIteratorControlHandle>,
1546    tx_id: u32,
1547}
1548
1549/// Set the the channel to be shutdown (see [`IpIteratorControlHandle::shutdown`])
1550/// if the responder is dropped without sending a response, so that the client
1551/// doesn't hang. To prevent this behavior, call `drop_without_shutdown`.
1552impl std::ops::Drop for IpIteratorNextResponder {
1553    fn drop(&mut self) {
1554        self.control_handle.shutdown();
1555        // Safety: drops once, never accessed again
1556        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1557    }
1558}
1559
1560impl fidl::endpoints::Responder for IpIteratorNextResponder {
1561    type ControlHandle = IpIteratorControlHandle;
1562
1563    fn control_handle(&self) -> &IpIteratorControlHandle {
1564        &self.control_handle
1565    }
1566
1567    fn drop_without_shutdown(mut self) {
1568        // Safety: drops once, never accessed again due to mem::forget
1569        unsafe { std::mem::ManuallyDrop::drop(&mut self.control_handle) };
1570        // Prevent Drop from running (which would shut down the channel)
1571        std::mem::forget(self);
1572    }
1573}
1574
1575impl IpIteratorNextResponder {
1576    /// Sends a response to the FIDL transaction.
1577    ///
1578    /// Sets the channel to shutdown if an error occurs.
1579    pub fn send(
1580        self,
1581        mut sockets: &[IpSocketState],
1582        mut has_more: bool,
1583    ) -> Result<(), fidl::Error> {
1584        let _result = self.send_raw(sockets, has_more);
1585        if _result.is_err() {
1586            self.control_handle.shutdown();
1587        }
1588        self.drop_without_shutdown();
1589        _result
1590    }
1591
1592    /// Similar to "send" but does not shutdown the channel if an error occurs.
1593    pub fn send_no_shutdown_on_err(
1594        self,
1595        mut sockets: &[IpSocketState],
1596        mut has_more: bool,
1597    ) -> Result<(), fidl::Error> {
1598        let _result = self.send_raw(sockets, has_more);
1599        self.drop_without_shutdown();
1600        _result
1601    }
1602
1603    fn send_raw(
1604        &self,
1605        mut sockets: &[IpSocketState],
1606        mut has_more: bool,
1607    ) -> Result<(), fidl::Error> {
1608        self.control_handle.inner.send::<IpIteratorNextResponse>(
1609            (sockets, has_more),
1610            self.tx_id,
1611            0x3d50aa08ce641a6b,
1612            fidl::encoding::DynamicFlags::empty(),
1613        )
1614    }
1615}
1616
1617mod internal {
1618    use super::*;
1619
1620    impl fidl::encoding::ResourceTypeMarker for DiagnosticsIterateIpRequest {
1621        type Borrowed<'a> = &'a mut Self;
1622        fn take_or_borrow<'a>(
1623            value: &'a mut <Self as fidl::encoding::TypeMarker>::Owned,
1624        ) -> Self::Borrowed<'a> {
1625            value
1626        }
1627    }
1628
1629    unsafe impl fidl::encoding::TypeMarker for DiagnosticsIterateIpRequest {
1630        type Owned = Self;
1631
1632        #[inline(always)]
1633        fn inline_align(_context: fidl::encoding::Context) -> usize {
1634            8
1635        }
1636
1637        #[inline(always)]
1638        fn inline_size(_context: fidl::encoding::Context) -> usize {
1639            24
1640        }
1641    }
1642
1643    unsafe impl
1644        fidl::encoding::Encode<
1645            DiagnosticsIterateIpRequest,
1646            fidl::encoding::DefaultFuchsiaResourceDialect,
1647        > for &mut DiagnosticsIterateIpRequest
1648    {
1649        #[inline]
1650        unsafe fn encode(
1651            self,
1652            encoder: &mut fidl::encoding::Encoder<
1653                '_,
1654                fidl::encoding::DefaultFuchsiaResourceDialect,
1655            >,
1656            offset: usize,
1657            _depth: fidl::encoding::Depth,
1658        ) -> fidl::Result<()> {
1659            encoder.debug_check_bounds::<DiagnosticsIterateIpRequest>(offset);
1660            // Delegate to tuple encoding.
1661            fidl::encoding::Encode::<DiagnosticsIterateIpRequest, fidl::encoding::DefaultFuchsiaResourceDialect>::encode(
1662                (
1663                    <fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<IpIteratorMarker>> as fidl::encoding::ResourceTypeMarker>::take_or_borrow(&mut self.s),
1664                    <Extensions as fidl::encoding::ValueTypeMarker>::borrow(&self.extensions),
1665                    <fidl::encoding::Vector<IpSocketMatcher, 128> as fidl::encoding::ValueTypeMarker>::borrow(&self.matchers),
1666                ),
1667                encoder, offset, _depth
1668            )
1669        }
1670    }
1671    unsafe impl<
1672        T0: fidl::encoding::Encode<
1673                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<IpIteratorMarker>>,
1674                fidl::encoding::DefaultFuchsiaResourceDialect,
1675            >,
1676        T1: fidl::encoding::Encode<Extensions, fidl::encoding::DefaultFuchsiaResourceDialect>,
1677        T2: fidl::encoding::Encode<
1678                fidl::encoding::Vector<IpSocketMatcher, 128>,
1679                fidl::encoding::DefaultFuchsiaResourceDialect,
1680            >,
1681    >
1682        fidl::encoding::Encode<
1683            DiagnosticsIterateIpRequest,
1684            fidl::encoding::DefaultFuchsiaResourceDialect,
1685        > for (T0, T1, T2)
1686    {
1687        #[inline]
1688        unsafe fn encode(
1689            self,
1690            encoder: &mut fidl::encoding::Encoder<
1691                '_,
1692                fidl::encoding::DefaultFuchsiaResourceDialect,
1693            >,
1694            offset: usize,
1695            depth: fidl::encoding::Depth,
1696        ) -> fidl::Result<()> {
1697            encoder.debug_check_bounds::<DiagnosticsIterateIpRequest>(offset);
1698            // Zero out padding regions. There's no need to apply masks
1699            // because the unmasked parts will be overwritten by fields.
1700            // Write the fields.
1701            self.0.encode(encoder, offset + 0, depth)?;
1702            self.1.encode(encoder, offset + 4, depth)?;
1703            self.2.encode(encoder, offset + 8, depth)?;
1704            Ok(())
1705        }
1706    }
1707
1708    impl fidl::encoding::Decode<Self, fidl::encoding::DefaultFuchsiaResourceDialect>
1709        for DiagnosticsIterateIpRequest
1710    {
1711        #[inline(always)]
1712        fn new_empty() -> Self {
1713            Self {
1714                s: fidl::new_empty!(
1715                    fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<IpIteratorMarker>>,
1716                    fidl::encoding::DefaultFuchsiaResourceDialect
1717                ),
1718                extensions: fidl::new_empty!(
1719                    Extensions,
1720                    fidl::encoding::DefaultFuchsiaResourceDialect
1721                ),
1722                matchers: fidl::new_empty!(fidl::encoding::Vector<IpSocketMatcher, 128>, fidl::encoding::DefaultFuchsiaResourceDialect),
1723            }
1724        }
1725
1726        #[inline]
1727        unsafe fn decode(
1728            &mut self,
1729            decoder: &mut fidl::encoding::Decoder<
1730                '_,
1731                fidl::encoding::DefaultFuchsiaResourceDialect,
1732            >,
1733            offset: usize,
1734            _depth: fidl::encoding::Depth,
1735        ) -> fidl::Result<()> {
1736            decoder.debug_check_bounds::<Self>(offset);
1737            // Verify that padding bytes are zero.
1738            fidl::decode!(
1739                fidl::encoding::Endpoint<fidl::endpoints::ServerEnd<IpIteratorMarker>>,
1740                fidl::encoding::DefaultFuchsiaResourceDialect,
1741                &mut self.s,
1742                decoder,
1743                offset + 0,
1744                _depth
1745            )?;
1746            fidl::decode!(
1747                Extensions,
1748                fidl::encoding::DefaultFuchsiaResourceDialect,
1749                &mut self.extensions,
1750                decoder,
1751                offset + 4,
1752                _depth
1753            )?;
1754            fidl::decode!(fidl::encoding::Vector<IpSocketMatcher, 128>, fidl::encoding::DefaultFuchsiaResourceDialect, &mut self.matchers, decoder, offset + 8, _depth)?;
1755            Ok(())
1756        }
1757    }
1758}