Skip to main content

SrtListener

Struct SrtListener 

Source
pub struct SrtListener { /* private fields */ }
Available on crate feature tokio only.
Expand description

An SRT listener that accepts incoming Caller connections.

§One socket, many connections (issue #1029)

Every connection this listener accepts shares its single bound socket — unlike SrtSocket::connect, which binds a fresh, unshared socket per connection. recv_from on a shared socket delivers each datagram to whichever waiting caller happens to be polled next, not whichever caller the datagram is actually addressed to: if both this listener’s own accept loop and one or more accepted connections’ driver tasks each called recv_from on the same socket, a datagram belonging to one connection could be handed to a completely different one (which would then just discard it as foreign), silently losing it for its rightful recipient. So exactly one task ever calls recv_from on udp: the routing pump spawned once in SrtListener::bind. It demultiplexes the way libsrt does (item 2, draft §4.3.1): a Destination Socket ID of 0 (every handshake packet this crate’s Caller ever sends, per the dest_socket_id fix in caller.rs) always means “not yet an established connection” and goes to unrouted_rx (accept’s own input); any other ID must match an entry in routes and that entry’s accepted source address, or the datagram is dropped — a stray packet naming an ID that was never accepted (or accepted from a different address) has nowhere legitimate to go.

A repeated CONCLUSION from an already-accepted Caller (its copy of our response was lost) carries Destination Socket ID 0 too, so it reaches the listener’s background task, which answers it again — no one has to be polling accept for that.

§Lifetime (defect 3)

Handshakes advance in a tracked background task, not inside accept; the routing pump is a second tracked task. Both end on a CancellationToken, fired when the last of {this handle, every accepted SrtSocket} is dropped — so an idle listener releases its UDP port the moment the handle is dropped, while connections it already accepted keep being routed until they too are gone.

Implementations§

Source§

impl SrtListener

Source

pub async fn bind<A: ToSocketAddrs>( addr: A, config: SrtSocketConfig, ) -> Result<Self>

Bind an SRT listener on addr.

§Encryption

A listener configured without a passphrase rejects any peer that asks for encryption (a Key Material extension or a non-zero Encryption Field). A listener configured with one negotiates keys and encrypts / decrypts the data path.

Source

pub fn unrouted_dropped(&self) -> u64

Datagrams dropped because the candidate-new-connection queue was full (item 4) — a handshake flood outrunning the listener’s handshake task — or because they exceeded IoConfig::max_datagram.

Source

pub fn accept_overflow_dropped(&self) -> u64

Connections that completed their handshake but were dropped because accept was not keeping up (the pending-accept queue holds 64); each dropped peer is sent a SHUTDOWN.

Source

pub fn send_errors(&self) -> u64

Send failures the background task met while answering peers (for example an unreachable spoofed source). They are counted here and never surface from accept, so a flood of them cannot displace finished connections or end an accept loop.

Source

pub fn recv_buffer_size(&self) -> Result<usize>

The receive buffer the kernel granted the listener’s socket (SO_RCVBUF), in bytes. The kernel may grant less or more than UdpOptions::recv_buffer_bytes asked for (it clamps to a system maximum, and Linux doubles the request for its own bookkeeping), so a deployment checks this value rather than trusting the request.

§Errors

Error::Io when the socket option cannot be read.

Source

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

The local socket address the listener is bound to.

Source

pub async fn accept(&mut self) -> Result<SrtSocket>

Accept the next incoming SRT connection.

Handshakes progress in the background whether or not this is being polled; this only waits for a finished one. Send errors met while answering peers are counted (send_errors), not returned.

Trait Implementations§

Source§

impl Debug for SrtListener

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for SrtListener

§

impl Freeze for SrtListener
where *const ArcInner<ListenerLife> is !null: Freeze, PhantomData<ArcInner<ListenerLife>>: Freeze, *const ArcInner<UdpSocket> is !null: Freeze, PhantomData<ArcInner<UdpSocket>>: Freeze, *const ArcInner<Chan<Result<SrtSocket, Error>, Semaphore>> is !null: Freeze, PhantomData<ArcInner<Chan<Result<SrtSocket, Error>, Semaphore>>>: Freeze, *const ArcInner<Atomic<u64>> is !null: Freeze, PhantomData<ArcInner<Atomic<u64>>>: Freeze,

§

impl Move for SrtListener

§

impl RefUnwindSafe for SrtListener

§

impl Send for SrtListener
where Arc<ListenerLife>: Send, Arc<UdpSocket>: Send, Arc<Chan<Result<SrtSocket, Error>, Semaphore>>: Send, Arc<Atomic<u64>>: Send,

§

impl Sync for SrtListener
where Arc<ListenerLife>: Sync, Arc<UdpSocket>: Sync, Arc<Chan<Result<SrtSocket, Error>, Semaphore>>: Sync, Arc<Atomic<u64>>: Sync,

§

impl Unpin for SrtListener

§

impl UnsafeUnpin for SrtListener
where *const ArcInner<ListenerLife> is !null: UnsafeUnpin, PhantomData<ArcInner<ListenerLife>>: UnsafeUnpin, *const ArcInner<UdpSocket> is !null: UnsafeUnpin, PhantomData<ArcInner<UdpSocket>>: UnsafeUnpin, *const ArcInner<Chan<Result<SrtSocket, Error>, Semaphore>> is !null: UnsafeUnpin, PhantomData<ArcInner<Chan<Result<SrtSocket, Error>, Semaphore>>>: UnsafeUnpin, *const ArcInner<Atomic<u64>> is !null: UnsafeUnpin, PhantomData<ArcInner<Atomic<u64>>>: UnsafeUnpin,

§

impl UnwindSafe for SrtListener
where Arc<ListenerLife>: UnwindSafe, Arc<UdpSocket>: UnwindSafe, Arc<Chan<Result<SrtSocket, Error>, Semaphore>>: UnwindSafe, Arc<Atomic<u64>>: UnwindSafe,

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<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<T> Same for T

Source§

type Output = T

Should always be Self
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