Skip to content

Commit 2a65d09

Browse files
committed
docs(iroh): clarify ProtocolHandler::accept
Clarify at the connection is always dropped when `accept` returns, and that the AcceptError variant doesn't really matter
1 parent dd99737 commit 2a65d09

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

iroh/src/protocol.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,13 @@ pub trait ProtocolHandler: Send + Sync + std::fmt::Debug + 'static {
175175
///
176176
/// Can be implemented as `async fn accept(&self, connection: Connection) -> Result<()>`.
177177
///
178-
/// The returned future runs on a freshly spawned tokio task so it can be long-running.
178+
/// The returned future runs on a freshly spawned tokio task so it can be long-running. Once
179+
/// `accept()` returns, the connection is dropped. This means that it will be closed
180+
/// if there are no other clones of the connection. If there is a protocol error, you
181+
/// can use [`Connection::close`] to send an error code to the remote peer. Returning
182+
/// an `Err<AcceptError>` will also drop the connection and log a warning, but no
183+
/// dedicated error code will be sent to the peer, so it's recommended to explicitly
184+
/// close the connection within your accept handler.
179185
///
180186
/// When [`Router::shutdown`] is called, no further connections will be accepted, and
181187
/// the futures returned by [`Self::accept`] will be aborted after the future returned

0 commit comments

Comments
 (0)