Skip to content

Commit

Permalink
feat(api): exposing SendStream/RecvStream id() public APIs which retu…
Browse files Browse the repository at this point in the history
…rn StreamId

- Also minor improvement to display msg for error::Close type.
  • Loading branch information
bochaco authored and joshuef committed Oct 25, 2022
1 parent 9e3d432 commit 0bf7523
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ serde = { version = "1.0.117", features = ["derive"] }
thiserror = "1.0.23"
tokio = { version = "1.12.0", features = ["sync"] }
tracing = "~0.1.26"
webpki = "~0.21.3"
rustls = { version = "0.20.2", default-features = false, features = ["quic", "dangerous_configuration"] }
structopt = {version = "0.3.25", optional = true}

Expand Down
10 changes: 10 additions & 0 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ impl SendStream {
Self { inner }
}

/// Get the identity of this stream
pub fn id(&self) -> quinn::StreamId {
self.inner.id()
}

/// Set the priority of the send stream.
///
/// Every send stream has an initial priority of 0. Locally buffered data from streams with
Expand Down Expand Up @@ -248,6 +253,11 @@ impl RecvStream {
Self { inner }
}

/// Get the identity of this stream
pub fn id(&self) -> quinn::StreamId {
self.inner.id()
}

/// Get the next message sent by the peer over this stream.
pub async fn next(&mut self) -> Result<UsrMsgBytes, RecvError> {
match self.next_wire_msg().await? {
Expand Down
16 changes: 7 additions & 9 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,16 @@ pub enum Close {
impl fmt::Display for Close {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let (closed_by, error_code, reason): (_, &dyn fmt::Display, _) = match self {
Self::Local => return write!(f, "us"),
Self::Application { error_code, reason } => {
("application", error_code, String::from_utf8_lossy(reason))
}
Self::Transport { error_code, reason } => {
("transport", error_code, String::from_utf8_lossy(reason))
}
Self::Local => return write!(f, "we closed the connection"),
Self::Application { error_code, reason } => ("remote application", error_code, reason),
Self::Transport { error_code, reason } => ("transport layer", error_code, reason),
};
write!(
f,
"{} (error code: {}, reason: {})",
closed_by, error_code, reason
"{} closed the connection (error code: {}, reason: {})",
closed_by,
error_code,
String::from_utf8_lossy(reason)
)
}
}
Expand Down

0 comments on commit 0bf7523

Please sign in to comment.