-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Make streams owned by request/response that they are tied to. #6228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c7b3f25
a72d8e0
14b25d2
22a2dd5
bf2c3ba
b855a4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,13 @@ | ||
| use crate::types::{Method, Scheme}; | ||
| use bytes::Bytes; | ||
| use bytes::{BufMut, Bytes, BytesMut}; | ||
| use std::collections::HashMap; | ||
|
|
||
| #[derive(Clone, Default)] | ||
| pub struct Stream { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the usages of this struct, it seems that a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added. |
||
| pub closed: bool, | ||
| pub data: BytesMut, | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct WasiHttp { | ||
| pub request_id_base: u32, | ||
|
|
@@ -11,7 +17,7 @@ pub struct WasiHttp { | |
| pub requests: HashMap<u32, ActiveRequest>, | ||
| pub responses: HashMap<u32, ActiveResponse>, | ||
| pub fields: HashMap<u32, HashMap<String, Vec<String>>>, | ||
| pub streams: HashMap<u32, Bytes>, | ||
| pub streams: HashMap<u32, Stream>, | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
|
|
@@ -66,6 +72,23 @@ impl ActiveResponse { | |
| } | ||
| } | ||
|
|
||
| impl Stream { | ||
| pub fn new() -> Self { | ||
| Self::default() | ||
| } | ||
| } | ||
|
|
||
| impl From<Bytes> for Stream { | ||
| fn from(bytes: Bytes) -> Self { | ||
| let mut buf = BytesMut::with_capacity(bytes.len()); | ||
| buf.put(bytes); | ||
| Self { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we had a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
| closed: false, | ||
| data: buf, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl WasiHttp { | ||
| pub fn new() -> Self { | ||
| Self { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't
with_contextwork here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I'm following your suggestion, can you clarify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'm referring to this method on the
anyhow::Contexttrait https://docs.rs/anyhow/latest/anyhow/trait.Context.html#tymethod.with_contextIf it's in scope, you should be able to call
contextorwith_context(usually used withformat!and similar) on mostResultand allOptiontypes directly, thus eliminating the need forok_or_elseand explicitanyhow!invocationUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rvolosatovs I made those ok_or_else(|| anyhow!(...)) suggestions in a prior PR and wasn't aware that Context could make that more succinct. Thank you.
@brendandburns The suggested change here is
let st = self.streams.get_mut(&stream).with_context(|| format!("stream not found: {stream}"))?;, or maybe even....get_mut(&stream).context("stream not found")?if leaving out the stream number is ok - and it probably is, because (at least when using the component linker, I'm not sure if it works in module mode) bindgen is insertingtracingstatements which someone debugging can recover the values of the arguments from.