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