async_coap/send_desc/
multicast.rs

1// Copyright 2019 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15
16use super::send_desc_passthru_options;
17use super::*;
18
19/// Multicast send descriptor combinator created by the `multicast()` method on
20/// [`SendGet`], [`SendPut`], [`SendPost`], [`SendDelete`], and [`SendObserve`].
21///
22/// This send descriptor can yield multiple results, so it should be used with
23/// [`LocalEndpointExt::send_as_stream`], [`RemoteEndpointExt::send_as_stream`],
24/// and/or [`RemoteEndpointExt::send_to_as_stream`].
25#[derive(Debug)]
26pub struct Multicast<SD>(pub(crate) SD);
27
28impl<SD> SendDescMulticast for Multicast<SD> {}
29impl<SD: Default> Default for Multicast<SD> {
30    #[inline]
31    fn default() -> Self {
32        Self(Default::default())
33    }
34}
35
36impl<SD, IC> SendDesc<IC, ()> for Multicast<SD>
37where
38    SD: SendDesc<IC, ()> + Send,
39    IC: InboundContext,
40{
41    send_desc_passthru_options!(0);
42    send_desc_passthru_supports_option!(0);
43
44    fn delay_to_retransmit(&self, retransmits_sent: u32) -> Option<Duration> {
45        self.0.delay_to_retransmit(retransmits_sent)
46    }
47    fn delay_to_restart(&self) -> Option<Duration> {
48        self.0.delay_to_restart()
49    }
50    fn max_rtt(&self) -> Duration {
51        Duration::from_secs(8)
52    }
53    fn transmit_wait_duration(&self) -> Duration {
54        Duration::from_secs(8)
55    }
56
57    fn write_payload(
58        &self,
59        msg: &mut dyn MessageWrite,
60        socket_addr: &IC::SocketAddr,
61    ) -> Result<(), Error> {
62        self.0.write_payload(msg, socket_addr)?;
63        msg.set_msg_type(MsgType::Non);
64        Ok(())
65    }
66
67    fn handler(&mut self, context: Result<&IC, Error>) -> Result<ResponseStatus<()>, Error> {
68        context?;
69        Ok(ResponseStatus::Continue)
70    }
71}