embedded_tls/flush_policy.rs
1//! Flush policy for TLS sockets.
2//!
3//! Two strategies are provided:
4//! - `Relaxed`: close the TLS encryption buffer and hand the data to the transport
5//! delegate without forcing a transport-level flush.
6//! - `Strict`: in addition to handing the data to the transport delegate, also
7//! request a flush of the transport. For TCP transports this typically means
8//! waiting for an ACK (e.g. on embassy TCP sockets) before considering the
9//! data fully flushed.
10
11/// Policy controlling how TLS layer flushes encrypted data to the transport.
12#[derive(Clone, Copy, Debug, PartialEq, Eq)]
13pub enum FlushPolicy {
14 /// Close the TLS encryption buffer and pass bytes to the transport delegate.
15 /// Do not force a transport-level flush or wait for an ACK.
16 Relaxed,
17
18 /// In addition to passing bytes to the transport delegate, request a
19 /// transport-level flush and wait for confirmation (ACK) before returning.
20 Strict,
21}
22
23impl FlushPolicy {
24 /// Returns true when the transport delegate should be explicitly flushed.
25 ///
26 /// Relaxed -> false, Strict -> true.
27 pub fn flush_transport(&self) -> bool {
28 matches!(self, Self::Strict)
29 }
30}
31
32impl Default for FlushPolicy {
33 /// Default to `Strict` for compatibility with embedded-tls 0.17.0.
34 fn default() -> Self {
35 FlushPolicy::Strict
36 }
37}