Skip to content

Commit 791e636

Browse files
committed
fix: docs after review
1 parent 1d8f685 commit 791e636

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

iroh/src/protocol.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl From<quinn::ClosedStream> for AcceptError {
155155
#[derive(Debug, Snafu)]
156156
#[non_exhaustive]
157157
pub enum RouterError {
158-
#[snafu(display("The router actor closed"))]
158+
#[snafu(display("Endpoint closed"))]
159159
Closed {},
160160
}
161161

@@ -164,7 +164,7 @@ pub enum RouterError {
164164
#[snafu(module)]
165165
#[non_exhaustive]
166166
pub enum StopAcceptingError {
167-
#[snafu(display("The router actor closed"))]
167+
#[snafu(display("Endpoint closed"))]
168168
Closed {},
169169
#[snafu(display("The ALPN requested to be removed is not registered"))]
170170
UnknownAlpn {},
@@ -381,16 +381,15 @@ impl Router {
381381
self.cancel_token.is_cancelled()
382382
}
383383

384-
/// Adds a protocol to the list of accepted protocols.
384+
/// Accepts incoming connections with this `alpn` via [`ProtocolHandler`].
385385
///
386-
/// Configures the router to accept the [`ProtocolHandler`] when receiving a connection
387-
/// with this `alpn`.
386+
/// After this function returns, new connections with this `alpn` will be handled
387+
/// by the passed `handler`.
388388
///
389-
/// Once the function yields, new connections with this `alpn` will be handled.
390-
///
391-
/// If a protocol handler was already registered for `alpn`, the previous handler will be shutdown.
392-
///
393-
/// Returns `true` if
389+
/// If a protocol handler was already registered for `alpn`, the previous handler will be
390+
/// shutdown. Existing connections will not be aborted by the router, but some protocol
391+
/// handlers may abort existing connnections in their [`Router::shutdown`] implementation.
392+
/// Consult the documentation of the protocol handler to see if that is the case.
394393
pub async fn accept(
395394
&self,
396395
alpn: impl AsRef<[u8]>,
@@ -408,10 +407,16 @@ impl Router {
408407
reply_rx.await.map_err(|_| RouterError::Closed {})
409408
}
410409

411-
/// Stops accepting a protocol.
410+
/// Stops accepting connections with this `alpn`.
411+
///
412+
/// After this function returns, new connections with `alpn` will no longer be accepted.
413+
///
414+
/// If a protocol handler was registered for `alpn`, the handler will be
415+
/// shutdown. Existing connections will not be aborted by the router, but some protocol
416+
/// handlers may abort existing connnections in their [`Router::shutdown`] implementation.
417+
/// Consult the documentation of the protocol handler to see if that is the case.
412418
///
413-
/// Note that this has only an effect on new connections. Existing connections that were
414-
/// accepted with `alpn` won't be closed when calling [`Router::stop_accepting`].
419+
/// Returns an error if the router has been shutdown or no protocol is registered for `alpn`.
415420
pub async fn stop_accepting(&self, alpn: impl AsRef<[u8]>) -> Result<(), StopAcceptingError> {
416421
let (reply, reply_rx) = oneshot::channel();
417422
self.tx
@@ -424,7 +429,7 @@ impl Router {
424429
reply_rx.await.map_err(|_| StopAcceptingError::Closed {})?
425430
}
426431

427-
/// Shuts down the accept loop cleanly.
432+
/// Shuts down the accept loop and endpoint cleanly.
428433
///
429434
/// When this function returns, all [`ProtocolHandler`]s will be shutdown and
430435
/// `Endpoint::close` will have been called.
@@ -459,8 +464,7 @@ impl RouterBuilder {
459464
}
460465
}
461466

462-
/// Configures the router to accept the [`ProtocolHandler`] when receiving a connection
463-
/// with this `alpn`.
467+
/// Configures the router to accept incoming connections with this `alpn` via [`ProtocolHandler`].
464468
pub fn accept(self, alpn: impl AsRef<[u8]>, handler: impl ProtocolHandler) -> Self {
465469
self.protocols
466470
.insert(alpn.as_ref().to_vec(), Arc::new(handler));

0 commit comments

Comments
 (0)