s2n_quic_transport/contexts/
mod.rs

1// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Defines Context traits, which are passed to various lifecycle callbacks
5//! within the connection in order to collect data
6
7use crate::{connection::InternalConnectionId, transmission, wakeup_queue::WakeupHandle};
8
9pub use transmission::Writer as WriteContext;
10
11/// Enumerates error values for `on_transmit` calls
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum OnTransmitError {
14    /// It was not possible to write a frame
15    CouldNotWriteFrame,
16    /// It was not possible to obtain a large enough space for writing a frame
17    CouldNotAcquireEnoughSpace,
18}
19
20/// Enumerates error values for `on_transmit` calls on connections
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
22pub enum ConnectionOnTransmitError {
23    /// It was not possible to obtain a datagram to write into
24    NoDatagram,
25}
26
27/// The context parameter which is passed from all external API calls
28pub struct ConnectionApiCallContext<'a> {
29    wakeup_handle: &'a WakeupHandle<InternalConnectionId>,
30}
31
32impl<'a> ConnectionApiCallContext<'a> {
33    /// Creates an [`ConnectionApiCallContext`] from a [`WakeupHandle`]
34    pub fn from_wakeup_handle(wakeup_handle: &'a WakeupHandle<InternalConnectionId>) -> Self {
35        Self { wakeup_handle }
36    }
37
38    /// Returns a reference to the WakeupHandle
39    pub fn wakeup_handle(&mut self) -> &WakeupHandle<InternalConnectionId> {
40        self.wakeup_handle
41    }
42}
43
44#[cfg(test)]
45pub mod testing {
46    pub use crate::transmission::writer::testing::{Writer as MockWriteContext, *};
47}