Skip to content

Commit

Permalink
Merge pull request #148 from hapsoc/no-write-task
Browse files Browse the repository at this point in the history
feat: Get rid of write task
  • Loading branch information
fasterthanlime authored Mar 12, 2024
2 parents 49e6d13 + 0a04234 commit 67bbd06
Show file tree
Hide file tree
Showing 10 changed files with 1,138 additions and 1,123 deletions.
2 changes: 1 addition & 1 deletion crates/fluke-buffet/src/roll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ impl RollMut {
init: 0,
};
let (res, mut read_into) = r.read(read_into).await;
tracing::trace!(init = %read_into.init, "read_into done!");
tracing::trace!("read_into got {} bytes", read_into.init);
read_into.buf.len += read_into.init;
(res, read_into.buf)
}
Expand Down
10 changes: 5 additions & 5 deletions crates/fluke/src/h2/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tracing::warn;

use super::{
parse::StreamId,
types::{H2ConnEvent, H2Event, H2EventPayload},
types::{H2Event, H2EventPayload},
};
use crate::{h1::body::BodyWriteMode, Encoder, Response};

Expand All @@ -16,16 +16,16 @@ pub(crate) enum EncoderState {

pub struct H2Encoder {
pub(crate) stream_id: StreamId,
pub(crate) tx: mpsc::Sender<H2ConnEvent>,
pub(crate) tx: mpsc::Sender<H2Event>,
pub(crate) state: EncoderState,
}

impl H2Encoder {
fn event(&self, payload: H2EventPayload) -> H2ConnEvent {
H2ConnEvent::ServerEvent(H2Event {
fn event(&self, payload: H2EventPayload) -> H2Event {
H2Event {
payload,
stream_id: self.stream_id,
})
}
}

async fn send(&self, payload: H2EventPayload) -> eyre::Result<()> {
Expand Down
2 changes: 0 additions & 2 deletions crates/fluke/src/h2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ pub(crate) mod parse;

mod body;
mod encode;
mod read;
mod types;
mod write;
79 changes: 78 additions & 1 deletion crates/fluke/src/h2/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,90 @@ impl fmt::Display for StreamId {
}

/// See https://httpwg.org/specs/rfc9113.html#FrameHeader
#[derive(Debug)]
pub struct Frame {
pub frame_type: FrameType,
pub reserved: u8,
pub stream_id: StreamId,
pub len: u32,
}

impl fmt::Debug for Frame {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if self.stream_id.0 == 0 {
write!(f, "Conn:")?;
} else {
write!(f, "#{}:", self.stream_id.0)?;
}

let name = match &self.frame_type {
FrameType::Data(_) => "Data",
FrameType::Headers(_) => "Headers",
FrameType::Priority => "Priority",
FrameType::RstStream => "RstStream",
FrameType::Settings(_) => "Settings",
FrameType::PushPromise => "PushPromise",
FrameType::Ping(_) => "Ping",
FrameType::GoAway => "GoAway",
FrameType::WindowUpdate => "WindowUpdate",
FrameType::Continuation(_) => "Continuation",
FrameType::Unknown(EncodedFrameType { ty, flags }) => {
return write!(f, "UnknownFrame({:#x}, {:#x})", ty, flags)
}
};
let mut s = f.debug_struct(name);

if self.reserved != 0 {
s.field("reserved", &self.reserved);
}
if self.len > 0 {
s.field("len", &self.len);
}

// now write flags with DisplayDebug
struct DisplayDebug<'a, D: fmt::Display>(&'a D);
impl<'a, D: fmt::Display> fmt::Debug for DisplayDebug<'a, D> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self.0, f)
}
}

// for all the variants with flags, add a flags field, of value
// &DisplayDebug(flags)
match &self.frame_type {
FrameType::Data(flags) => {
if !flags.is_empty() {
s.field("flags", &DisplayDebug(flags));
}
}
FrameType::Headers(flags) => {
if !flags.is_empty() {
s.field("flags", &DisplayDebug(flags));
}
}
FrameType::Settings(flags) => {
if !flags.is_empty() {
s.field("flags", &DisplayDebug(flags));
}
}
FrameType::Ping(flags) => {
if !flags.is_empty() {
s.field("flags", &DisplayDebug(flags));
}
}
FrameType::Continuation(flags) => {
if !flags.is_empty() {
s.field("flags", &DisplayDebug(flags));
}
}
_ => {
// muffin
}
}

s.finish()
}
}

impl Frame {
/// Create a new frame with the given type and stream ID.
pub fn new(frame_type: FrameType, stream_id: StreamId) -> Self {
Expand Down Expand Up @@ -503,6 +579,7 @@ impl Settings {
const MAX_FRAME_SIZE_ALLOWED_RANGE: RangeInclusive<u32> = (1 << 14)..=((1 << 24) - 1);

pub fn parse(mut i: Roll) -> IResult<Roll, Self> {
tracing::trace!("parsing settings frame, roll length: {}", i.len());
let mut settings = Self::default();

while !i.is_empty() {
Expand Down
Loading

0 comments on commit 67bbd06

Please sign in to comment.