Skip to content

Commit

Permalink
More tokenization
Browse files Browse the repository at this point in the history
  • Loading branch information
maddeleine committed Sep 18, 2024
1 parent 8485ffd commit 0a39346
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 116 deletions.
70 changes: 0 additions & 70 deletions dc/s2n-quic-dc/src/event/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,40 +187,6 @@ mod traits {
meta: &ConnectionMeta,
info: &ConnectionInfo,
) -> Self::ConnectionContext;
#[doc = r" The period at which `on_supervisor_timeout` is called"]
#[doc = r""]
#[doc = r" If multiple `event::Subscriber`s are composed together, the minimum `supervisor_timeout`"]
#[doc = r" across all `event::Subscriber`s will be used."]
#[doc = r""]
#[doc = r" If the `supervisor_timeout()` is `None` across all `event::Subscriber`s, connection supervision"]
#[doc = r" will cease for the remaining lifetime of the connection and `on_supervisor_timeout` will no longer"]
#[doc = r" be called."]
#[doc = r""]
#[doc = r" It is recommended to avoid setting this value less than ~100ms, as short durations"]
#[doc = r" may lead to higher CPU utilization."]
#[allow(unused_variables)]
fn supervisor_timeout(
&self,
conn_context: &Self::ConnectionContext,
meta: &ConnectionMeta,
context: &supervisor::Context,
) -> Option<Duration> {
None
}
#[doc = r" Called for each `supervisor_timeout` to determine any action to take on the connection based on the `supervisor::Outcome`"]
#[doc = r""]
#[doc = r" If multiple `event::Subscriber`s are composed together, the minimum `supervisor_timeout`"]
#[doc = r" across all `event::Subscriber`s will be used, and thus `on_supervisor_timeout` may be called"]
#[doc = r" earlier than the `supervisor_timeout` for a given `event::Subscriber` implementation."]
#[allow(unused_variables)]
fn on_supervisor_timeout(
&self,
conn_context: &Self::ConnectionContext,
meta: &ConnectionMeta,
context: &supervisor::Context,
) -> supervisor::Outcome {
supervisor::Outcome::default()
}
#[doc = "Called when the `FrameSent` event is triggered"]
#[inline]
fn on_frame_sent(
Expand Down Expand Up @@ -280,42 +246,6 @@ mod traits {
)
}
#[inline]
fn supervisor_timeout(
&self,
conn_context: &Self::ConnectionContext,
meta: &ConnectionMeta,
context: &supervisor::Context,
) -> Option<Duration> {
let timeout_a = self.0.supervisor_timeout(&conn_context.0, meta, context);
let timeout_b = self.1.supervisor_timeout(&conn_context.1, meta, context);
match (timeout_a, timeout_b) {
(None, None) => None,
(None, Some(timeout)) | (Some(timeout), None) => Some(timeout),
(Some(a), Some(b)) => Some(a.min(b)),
}
}
#[inline]
fn on_supervisor_timeout(
&self,
conn_context: &Self::ConnectionContext,
meta: &ConnectionMeta,
context: &supervisor::Context,
) -> supervisor::Outcome {
let outcome_a = self.0.on_supervisor_timeout(&conn_context.0, meta, context);
let outcome_b = self.1.on_supervisor_timeout(&conn_context.1, meta, context);
match (outcome_a, outcome_b) {
(supervisor::Outcome::ImmediateClose { reason }, _)
| (_, supervisor::Outcome::ImmediateClose { reason }) => {
supervisor::Outcome::ImmediateClose { reason }
}
(supervisor::Outcome::Close { error_code }, _)
| (_, supervisor::Outcome::Close { error_code }) => {
supervisor::Outcome::Close { error_code }
}
_ => supervisor::Outcome::Continue,
}
}
#[inline]
fn on_frame_sent(
&self,
context: &Self::ConnectionContext,
Expand Down
146 changes: 100 additions & 46 deletions quic/s2n-quic-events/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,102 @@ impl OutputMode {
),
}
}

fn supervisor_timeout(&self) -> TokenStream {
match self {
OutputMode::Ref => quote!(),
OutputMode::Mut => quote!(
/// The period at which `on_supervisor_timeout` is called
///
/// If multiple `event::Subscriber`s are composed together, the minimum `supervisor_timeout`
/// across all `event::Subscriber`s will be used.
///
/// If the `supervisor_timeout()` is `None` across all `event::Subscriber`s, connection supervision
/// will cease for the remaining lifetime of the connection and `on_supervisor_timeout` will no longer
/// be called.
///
/// It is recommended to avoid setting this value less than ~100ms, as short durations
/// may lead to higher CPU utilization.
#[allow(unused_variables)]
fn supervisor_timeout(
&mut self,
conn_context: &mut Self::ConnectionContext,
meta: &ConnectionMeta,
context: &supervisor::Context,
) -> Option<Duration> {
None
}

/// Called for each `supervisor_timeout` to determine any action to take on the connection based on the `supervisor::Outcome`
///
/// If multiple `event::Subscriber`s are composed together, the minimum `supervisor_timeout`
/// across all `event::Subscriber`s will be used, and thus `on_supervisor_timeout` may be called
/// earlier than the `supervisor_timeout` for a given `event::Subscriber` implementation.
#[allow(unused_variables)]
fn on_supervisor_timeout(
&mut self,
conn_context: &mut Self::ConnectionContext,
meta: &ConnectionMeta,
context: &supervisor::Context,
) -> supervisor::Outcome {
supervisor::Outcome::default()
}
),
}
}

fn supervisor_timeout_tuple(&self) -> TokenStream {
match self {
OutputMode::Ref => quote!(),
OutputMode::Mut => quote!(
#[inline]
fn supervisor_timeout(
&mut self,
conn_context: &mut Self::ConnectionContext,
meta: &ConnectionMeta,
context: &supervisor::Context,
) -> Option<Duration> {
let timeout_a = self
.0
.supervisor_timeout(&mut conn_context.0, meta, context);
let timeout_b = self
.1
.supervisor_timeout(&mut conn_context.1, meta, context);
match (timeout_a, timeout_b) {
(None, None) => None,
(None, Some(timeout)) | (Some(timeout), None) => Some(timeout),
(Some(a), Some(b)) => Some(a.min(b)),
}
}

#[inline]
fn on_supervisor_timeout(
&mut self,
conn_context: &mut Self::ConnectionContext,
meta: &ConnectionMeta,
context: &supervisor::Context,
) -> supervisor::Outcome {
let outcome_a =
self.0
.on_supervisor_timeout(&mut conn_context.0, meta, context);
let outcome_b =
self.1
.on_supervisor_timeout(&mut conn_context.1, meta, context);
match (outcome_a, outcome_b) {
(supervisor::Outcome::ImmediateClose { reason }, _)
| (_, supervisor::Outcome::ImmediateClose { reason }) => {
supervisor::Outcome::ImmediateClose { reason }
}
(supervisor::Outcome::Close { error_code }, _)
| (_, supervisor::Outcome::Close { error_code }) => {
supervisor::Outcome::Close { error_code }
}
_ => supervisor::Outcome::Continue,
}
}
),
}
}
}

impl ToTokens for OutputMode {
Expand Down Expand Up @@ -232,6 +328,8 @@ impl ToTokens for Output {
let lock = self.mode.lock();
let target_crate = self.mode.target_crate();
let supervisor = self.mode.supervisor();
let supervisor_timeout = self.mode.supervisor_timeout();
let supervisor_timeout_tuple = self.mode.supervisor_timeout_tuple();
let query_mut = self.mode.query_mut();
let query_mut_tuple = self.mode.query_mut_tuple();

Expand Down Expand Up @@ -400,31 +498,7 @@ impl ToTokens for Output {
/// Creates a context to be passed to each connection-related event
fn create_connection_context(&#mode self, meta: &ConnectionMeta, info: &ConnectionInfo) -> Self::ConnectionContext;

/// The period at which `on_supervisor_timeout` is called
///
/// If multiple `event::Subscriber`s are composed together, the minimum `supervisor_timeout`
/// across all `event::Subscriber`s will be used.
///
/// If the `supervisor_timeout()` is `None` across all `event::Subscriber`s, connection supervision
/// will cease for the remaining lifetime of the connection and `on_supervisor_timeout` will no longer
/// be called.
///
/// It is recommended to avoid setting this value less than ~100ms, as short durations
/// may lead to higher CPU utilization.
#[allow(unused_variables)]
fn supervisor_timeout(&#mode self, conn_context: &#mode Self::ConnectionContext, meta: &ConnectionMeta, context: &supervisor::Context) -> Option<Duration> {
None
}

/// Called for each `supervisor_timeout` to determine any action to take on the connection based on the `supervisor::Outcome`
///
/// If multiple `event::Subscriber`s are composed together, the minimum `supervisor_timeout`
/// across all `event::Subscriber`s will be used, and thus `on_supervisor_timeout` may be called
/// earlier than the `supervisor_timeout` for a given `event::Subscriber` implementation.
#[allow(unused_variables)]
fn on_supervisor_timeout(&#mode self, conn_context: &#mode Self::ConnectionContext, meta: &ConnectionMeta, context: &supervisor::Context) -> supervisor::Outcome {
supervisor::Outcome::default()
}
#supervisor_timeout

#subscriber

Expand Down Expand Up @@ -466,27 +540,7 @@ impl ToTokens for Output {
(self.0.create_connection_context(meta, info), self.1.create_connection_context(meta, info))
}

#[inline]
fn supervisor_timeout(&#mode self, conn_context: &#mode Self::ConnectionContext, meta: &ConnectionMeta, context: &supervisor::Context) -> Option<Duration> {
let timeout_a = self.0.supervisor_timeout(&#mode conn_context.0, meta, context);
let timeout_b = self.1.supervisor_timeout(&#mode conn_context.1, meta, context);
match (timeout_a, timeout_b) {
(None, None) => None,
(None, Some(timeout)) | (Some(timeout), None) => Some(timeout),
(Some(a), Some(b)) => Some(a.min(b)),
}
}

#[inline]
fn on_supervisor_timeout(&#mode self, conn_context: &#mode Self::ConnectionContext, meta: &ConnectionMeta, context: &supervisor::Context) -> supervisor::Outcome {
let outcome_a = self.0.on_supervisor_timeout(&#mode conn_context.0, meta, context);
let outcome_b = self.1.on_supervisor_timeout(&#mode conn_context.1, meta, context);
match (outcome_a, outcome_b) {
(supervisor::Outcome::ImmediateClose { reason }, _) | (_, supervisor::Outcome::ImmediateClose { reason }) => supervisor::Outcome::ImmediateClose { reason },
(supervisor::Outcome::Close { error_code }, _) | (_, supervisor::Outcome::Close { error_code }) => supervisor::Outcome::Close { error_code },
_ => supervisor::Outcome::Continue,
}
}
#supervisor_timeout_tuple

#tuple_subscriber

Expand Down

0 comments on commit 0a39346

Please sign in to comment.