Skip to main content

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