Skip to main content

TlsListener

Struct TlsListener 

Source
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>

Source

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.

Source

pub fn with_health(self, health: AcceptHealth) -> Self

Feeds this listener’s accept failures into a readiness probe.

Source

pub fn local_addr(&self) -> Result<SocketAddr>

Mirrors the trait method so callers need not import the trait to ask.

Source

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.

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)

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.

Source§

type Io = TlsStream<TcpStream>

The listener’s IO type.
Source§

type Addr = SocketAddr

The listener’s address type.
Source§

fn local_addr(&self) -> Result<Self::Addr>

Returns the local address that this listener is bound to.

Auto Trait Implementations§

§

impl<O> !Freeze for TlsListener<O>

§

impl<O> !RefUnwindSafe for TlsListener<O>

§

impl<O> !UnwindSafe for TlsListener<O>

§

impl<O> Forget for TlsListener<O>

§

impl<O> Move for TlsListener<O>

§

impl<O> Send for TlsListener<O>
where Arc<O>: Send,

§

impl<O> Sync for TlsListener<O>
where Arc<O>: Sync,

§

impl<O> Unpin for TlsListener<O>
where Arc<O>: Unpin,

§

impl<O> UnsafeUnpin for TlsListener<O>
where Arc<O>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<L> ListenerExt for L
where L: Listener,

Source§

fn tap_io<F>(self, tap_fn: F) -> TapIo<Self, F>
where F: FnMut(&mut Self::Io) + Send + 'static,

Run a mutable closure on every accepted Io. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more