Skip to main content

SrtSocket

Struct SrtSocket 

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

A handle to an established SRT connection over UDP.

Created by SrtSocket::connect (caller role) or SrtListener::accept (listener role). The protocol itself runs on a background tokio task the handle owns; send enqueues an application payload and recv awaits a delivered one. Dropping the handle sends the peer a SHUTDOWN (§3.2.7) and aborts the driver task.

Implementations§

Source§

impl SrtSocket

Source

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

Connect to a remote SRT peer as a Caller.

§Encryption

With crypto set in the HandshakeConfig, the adapter negotiates keys in the handshake and encrypts outgoing / decrypts incoming data packets (AES-CTR, draft section 6) on this connection.

§Errors

Error::Rejected carries the peer’s RejectionReason; Error::HandshakeTimedOut means the peer never answered within the handshake budget; Error::Handshake wraps an engine failure with the stage it happened in.

Source

pub async fn connect_from<A: ToSocketAddrs>( local_addr: SocketAddr, remote_addr: A, config: SrtSocketConfig, ) -> Result<Self>

Connect from a specific local address.

§Encryption

Like Self::connect, negotiates and applies payload encryption when crypto is set in the HandshakeConfig.

Source

pub async fn connect_from_socket<A: ToSocketAddrs>( socket: UdpSocket, remote_addr: A, config: SrtSocketConfig, ) -> Result<Self>

Like Self::connect_from, but takes an already-bound UDP socket instead of binding one. The socket’s own local address is used as the connection’s local endpoint, which lets a caller hold the port from bind to use and avoid a bind/read/drop/rebind race.

§Errors

Same as Self::connect_from.

Source

pub async fn rendezvous<A: ToSocketAddrs>( local_addr: SocketAddr, remote_addr: A, config: SrtSocketConfig, ) -> Result<Self>

Establish a connection with a peer in Rendezvous mode (draft-sharabayko-srt-01 §4.3.2): both sides bind a known local port and send to each other’s address at the same time, so neither is Caller or Listener; the cookie contest picks Initiator / Responder. Runs the sans-IO crate::rendezvous::RendezvousHandshake over a UDP socket bound to local_addr (its port must be the one the peer targets).

§Errors

Error::Rejected carries the peer’s RejectionReason; Error::HandshakeTimedOut means the peer never completed the exchange within the handshake budget.

Source

pub async fn rendezvous_from_socket<A: ToSocketAddrs>( socket: UdpSocket, remote_addr: A, config: SrtSocketConfig, ) -> Result<Self>

Like Self::rendezvous, but takes an already-bound UDP socket instead of binding one. The socket’s own local address is used as the connection’s local endpoint, which lets a caller hold the port from bind to use and avoid a bind/read/drop/rebind race.

§Errors

Same as Self::rendezvous.

Source

pub async fn send(&mut self, payload: &[u8]) -> Result<()>

Enqueue a payload for transmission to the peer.

Returns once the payload is handed to the driver task — actual transmission, ACK/NAK handling, and retransmission all happen on that task. Waits (applying backpressure) while the sender already holds a full flow window of unacknowledged packets or the hand-off queue is full. Fails only if the driver task has stopped (peer shut down, went silent, or a connection error).

Source

pub async fn send_bytes(&mut self, payload: Bytes) -> Result<()>

Like send but takes ownership of an already-built Bytes, so the hand-off to the driver task does not copy it.

Source

pub async fn close(&mut self) -> Result<Option<Damage>>

Close this connection after every handed-over packet has been acknowledged, or the caller’s CloseTimings bound has expired. Returns the damage report when the linger expired with packets still unacknowledged; the same report travels through Self::recv_event. Sending SHUTDOWN and ending the driver are waited for before this returns.

§Errors

Error::Io when the driver task can no longer be reached or it failed.

Source

pub fn peer_addr(&self) -> SocketAddr

The peer’s socket address.

Source

pub async fn recv_event(&mut self) -> Result<Option<SrtEvent>>

Receive the next item in delivery order: a payload or a damage report.

Returns None once the peer has shut down (or the driver task has stopped) and no further items will arrive. The caller’s DamagePolicy failing a report (Fail) ends the connection here with Error::Damage carrying the same report.

Source

pub async fn recv(&mut self) -> Result<Option<Bytes>>

Receive the next payload, waiting until one is available. Returns None once the peer has shut down (or the driver task has stopped) and no further payloads will arrive.

Damage reports that arrive before the next payload are held (they are not dropped): drain them with Self::next_damage, or use Self::recv_event to see both in order.

Source

pub fn next_damage(&mut self) -> Option<Damage>

The next damage report already received by a Self::recv call.

Source

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

The receive buffer the kernel granted this connection’s socket (SO_RCVBUF), in bytes; see SrtListener::recv_buffer_size for why it can differ from what was requested. For a connection accepted from a listener this is the listener’s socket.

§Errors

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

Source

pub fn stats(&self) -> SocketStats

A snapshot of this connection’s internal-backpressure drop counters (item 4) — datagrams or delivered payloads this adapter’s own bounded channels dropped because they were full, not wire-level loss.

Trait Implementations§

Source§

impl Debug for SrtSocket

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for SrtSocket

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl Forget for SrtSocket

§

impl Freeze for SrtSocket
where *const ArcInner<Chan<Outgoing, Semaphore>> is !null: Freeze, PhantomData<ArcInner<Chan<Outgoing, Semaphore>>>: Freeze, *const ArcInner<Chan<Delivered, Semaphore>> is !null: Freeze, PhantomData<ArcInner<Chan<Delivered, Semaphore>>>: Freeze, *const u8 is !null: Freeze, PhantomData<Damage>: Freeze, *const Header is !null: Freeze, PhantomData<()>: Freeze, *const ArcInner<Counters> is !null: Freeze, PhantomData<ArcInner<Counters>>: Freeze, *const ArcInner<UdpSocket> is !null: Freeze, PhantomData<ArcInner<UdpSocket>>: Freeze, *const ArcInner<Chan<(), Semaphore>> is !null: Freeze, PhantomData<ArcInner<Chan<(), Semaphore>>>: Freeze, *const ArcInner<Mutex<Option<Damage>>> is !null: Freeze, PhantomData<ArcInner<Mutex<Option<Damage>>>>: Freeze, *const ArcInner<ListenerLife> is !null: Freeze, PhantomData<ArcInner<ListenerLife>>: Freeze,

§

impl Move for SrtSocket

§

impl RefUnwindSafe for SrtSocket

§

impl Send for SrtSocket
where Arc<Chan<Outgoing, Semaphore>>: Send, Arc<Chan<Delivered, Semaphore>>: Send, RawVecInner: Send, NonZero<u32>: Send, &'static str: Send, JoinHandle<()>: Send, Arc<Counters>: Send, Arc<UdpSocket>: Send, Arc<Chan<(), Semaphore>>: Send, Arc<Mutex<Option<Damage>>>: Send, Arc<ListenerLife>: Send,

§

impl Sync for SrtSocket
where Arc<Chan<Outgoing, Semaphore>>: Sync, Arc<Chan<Delivered, Semaphore>>: Sync, RawVecInner: Sync, NonZero<u32>: Sync, JoinHandle<()>: Sync, Arc<Counters>: Sync, Arc<UdpSocket>: Sync, Arc<Chan<(), Semaphore>>: Sync, Arc<Mutex<Option<Damage>>>: Sync, Arc<ListenerLife>: Sync,

§

impl Unpin for SrtSocket
where Arc<Chan<Outgoing, Semaphore>>: Unpin, Receiver<Delivered>: Unpin, *const u8 is !null: Unpin, NonZero<u32>: Unpin, &'static str: Unpin, JoinHandle<()>: Unpin, Arc<Counters>: Unpin, Arc<UdpSocket>: Unpin, Arc<Chan<(), Semaphore>>: Unpin, Arc<Mutex<Option<Damage>>>: Unpin, Arc<ListenerLife>: Unpin,

§

impl UnsafeUnpin for SrtSocket
where *const ArcInner<Chan<Outgoing, Semaphore>> is !null: UnsafeUnpin, PhantomData<ArcInner<Chan<Outgoing, Semaphore>>>: UnsafeUnpin, *const ArcInner<Chan<Delivered, Semaphore>> is !null: UnsafeUnpin, PhantomData<ArcInner<Chan<Delivered, Semaphore>>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<Damage>: UnsafeUnpin, *const Header is !null: UnsafeUnpin, PhantomData<()>: UnsafeUnpin, *const ArcInner<Counters> is !null: UnsafeUnpin, PhantomData<ArcInner<Counters>>: UnsafeUnpin, *const ArcInner<UdpSocket> is !null: UnsafeUnpin, PhantomData<ArcInner<UdpSocket>>: UnsafeUnpin, *const ArcInner<Chan<(), Semaphore>> is !null: UnsafeUnpin, PhantomData<ArcInner<Chan<(), Semaphore>>>: UnsafeUnpin, *const ArcInner<Mutex<Option<Damage>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Option<Damage>>>>: UnsafeUnpin, *const ArcInner<ListenerLife> is !null: UnsafeUnpin, PhantomData<ArcInner<ListenerLife>>: UnsafeUnpin,

§

impl UnwindSafe for SrtSocket
where Arc<Chan<Outgoing, Semaphore>>: UnwindSafe, Arc<Chan<Delivered, Semaphore>>: UnwindSafe, RawVecInner: UnwindSafe, NonZero<u32>: UnwindSafe, &'static str: UnwindSafe, JoinHandle<()>: UnwindSafe, Arc<Counters>: UnwindSafe, Arc<UdpSocket>: UnwindSafe, Arc<Chan<(), Semaphore>>: UnwindSafe, Arc<Mutex<Option<Damage>>>: UnwindSafe, Arc<ListenerLife>: 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