pub struct TlsListener<O: TlsObserver> { /* private fields */ }Expand description
A bound TLS listener plus the watch that keeps its certificate current.
The watcher is owned here because dropping it silently stops reloads; tying its lifetime to the listener’s means the two cannot get separated.
Implementations§
Source§impl<O: TlsObserver> TlsListener<O>
impl<O: TlsObserver> TlsListener<O>
Sourcepub fn new(
tcp: TcpListener,
settings: TlsSettings,
observer: Arc<O>,
) -> Result<Self, TlsError>
pub fn new( tcp: TcpListener, settings: TlsSettings, observer: Arc<O>, ) -> Result<Self, TlsError>
Terminates TLS on an already-bound listener, loading the initial certificate and starting the watch for rotations.
Failing to load at startup is fatal, unlike failing to reload later: a process that comes up without a usable certificate has nothing to serve.
Sourcepub fn with_health(self, health: AcceptHealth) -> Self
pub fn with_health(self, health: AcceptHealth) -> Self
Feeds this listener’s accept failures into a readiness probe.
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
Mirrors the trait method so callers need not import the trait to ask.
Sourcepub async fn accept_tls(&mut self) -> Result<(TlsStream<TcpStream>, SocketAddr)>
pub async fn accept_tls(&mut self) -> Result<(TlsStream<TcpStream>, SocketAddr)>
Accepts the next connection whose TLS handshake has completed.
Handshakes run as spawned tasks under a deadline and a fixed ceiling rather than inline, so one slow client cannot hold up every other connection waiting to be accepted.
Temporary accept failures are retried with a backoff and reported through the observer. An error is returned only when the listening socket itself is unusable, so the caller can stop instead of retrying forever.
Trait Implementations§
Source§impl<O: TlsObserver> Listener for TlsListener<O>
Available on crate feature axum only.Lets an axum server accept from this listener.
impl<O: TlsObserver> Listener for TlsListener<O>
axum only.Lets an axum server accept from this listener.
Behind a feature because the reload machinery has nothing to do with axum -
non-HTTP callers use TlsListener::accept_tls directly without
compiling a web framework to get certificate rotation.
Source§async fn accept(&mut self) -> (Self::Io, Self::Addr)
async fn accept(&mut self) -> (Self::Io, Self::Addr)
axum cannot be told a listener has failed, so a fatal error parks
this listener after TlsObserver::listener_failed. A caller that must
stop on it should accept with TlsListener::accept_tls instead.