Skip to content

Commit

Permalink
feat: add optional reason for closing a connection
Browse files Browse the repository at this point in the history
BREAKING_CHANGE: The close api now needs an optional reason passed in.

Here we can specifigy _why_ a connection was closed
(or fallback to simply stating it was intentional and triggered via
qp2p)
  • Loading branch information
joshuef committed Jan 11, 2022
1 parent 0675024 commit 8ba42b5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ impl Connection {
/// This is not a graceful close - pending operations will fail immediately with
/// [`ConnectionError::Closed`]`(`[`Close::Local`]`)`, and data on unfinished streams is not
/// guaranteed to be delivered.
pub fn close(&self) {
self.inner.close(0u8.into(), b"");
pub fn close(&self, reason: Option<String>) {
let reason = reason
.unwrap_or_else(|| "The connection was closed intentionally by qp2p.".to_string());
self.inner.close(0u8.into(), &reason.into_bytes());
}

async fn send_uni(&self, msg: Bytes, priority: i32) -> Result<(), SendError> {
Expand Down

0 comments on commit 8ba42b5

Please sign in to comment.