|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +// DO NOT MODIFY THIS FILE |
| 5 | +// This file was generated with the `s2n-quic-events` crate and any required |
| 6 | +// changes should be made there. |
| 7 | + |
| 8 | +use crate::event::{self, api, metrics::Recorder}; |
| 9 | +use core::sync::atomic::{AtomicU32, Ordering}; |
| 10 | +pub(crate) mod aggregate; |
| 11 | +pub(crate) mod probe; |
| 12 | +#[derive(Debug)] |
| 13 | +pub struct Subscriber<S: event::Subscriber> |
| 14 | +where |
| 15 | + S::ConnectionContext: Recorder, |
| 16 | +{ |
| 17 | + subscriber: S, |
| 18 | +} |
| 19 | +impl<S: event::Subscriber> Subscriber<S> |
| 20 | +where |
| 21 | + S::ConnectionContext: Recorder, |
| 22 | +{ |
| 23 | + pub fn new(subscriber: S) -> Self { |
| 24 | + Self { subscriber } |
| 25 | + } |
| 26 | +} |
| 27 | +pub struct Context<R: Recorder> { |
| 28 | + recorder: R, |
| 29 | + application_write: AtomicU32, |
| 30 | + application_read: AtomicU32, |
| 31 | +} |
| 32 | +impl<S: event::Subscriber> event::Subscriber for Subscriber<S> |
| 33 | +where |
| 34 | + S::ConnectionContext: Recorder, |
| 35 | +{ |
| 36 | + type ConnectionContext = Context<S::ConnectionContext>; |
| 37 | + fn create_connection_context( |
| 38 | + &self, |
| 39 | + meta: &api::ConnectionMeta, |
| 40 | + info: &api::ConnectionInfo, |
| 41 | + ) -> Self::ConnectionContext { |
| 42 | + Context { |
| 43 | + recorder: self.subscriber.create_connection_context(meta, info), |
| 44 | + application_write: AtomicU32::new(0), |
| 45 | + application_read: AtomicU32::new(0), |
| 46 | + } |
| 47 | + } |
| 48 | + #[inline] |
| 49 | + fn on_application_write( |
| 50 | + &self, |
| 51 | + context: &Self::ConnectionContext, |
| 52 | + meta: &api::ConnectionMeta, |
| 53 | + event: &api::ApplicationWrite, |
| 54 | + ) { |
| 55 | + context.application_write.fetch_add(1, Ordering::Relaxed); |
| 56 | + self.subscriber |
| 57 | + .on_application_write(&context.recorder, meta, event); |
| 58 | + } |
| 59 | + #[inline] |
| 60 | + fn on_application_read( |
| 61 | + &self, |
| 62 | + context: &Self::ConnectionContext, |
| 63 | + meta: &api::ConnectionMeta, |
| 64 | + event: &api::ApplicationRead, |
| 65 | + ) { |
| 66 | + context.application_read.fetch_add(1, Ordering::Relaxed); |
| 67 | + self.subscriber |
| 68 | + .on_application_read(&context.recorder, meta, event); |
| 69 | + } |
| 70 | +} |
| 71 | +impl<R: Recorder> Drop for Context<R> { |
| 72 | + fn drop(&mut self) { |
| 73 | + self.recorder.increment_counter( |
| 74 | + "application_write", |
| 75 | + self.application_write.load(Ordering::Relaxed) as _, |
| 76 | + ); |
| 77 | + self.recorder.increment_counter( |
| 78 | + "application_read", |
| 79 | + self.application_read.load(Ordering::Relaxed) as _, |
| 80 | + ); |
| 81 | + } |
| 82 | +} |
0 commit comments