pub struct SrtSocket { /* private fields */ }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
impl SrtSocket
Sourcepub async fn connect<A: ToSocketAddrs>(
remote_addr: A,
config: SrtSocketConfig,
) -> Result<Self>
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.
Sourcepub async fn connect_from<A: ToSocketAddrs>(
local_addr: SocketAddr,
remote_addr: A,
config: SrtSocketConfig,
) -> Result<Self>
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.
Sourcepub async fn connect_from_socket<A: ToSocketAddrs>(
socket: UdpSocket,
remote_addr: A,
config: SrtSocketConfig,
) -> Result<Self>
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.
Sourcepub async fn rendezvous<A: ToSocketAddrs>(
local_addr: SocketAddr,
remote_addr: A,
config: SrtSocketConfig,
) -> Result<Self>
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.
Sourcepub async fn rendezvous_from_socket<A: ToSocketAddrs>(
socket: UdpSocket,
remote_addr: A,
config: SrtSocketConfig,
) -> Result<Self>
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.
Sourcepub async fn send(&mut self, payload: &[u8]) -> Result<()>
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).
Sourcepub async fn send_bytes(&mut self, payload: Bytes) -> Result<()>
pub async fn send_bytes(&mut self, payload: Bytes) -> Result<()>
Sourcepub fn peer_addr(&self) -> SocketAddr
pub fn peer_addr(&self) -> SocketAddr
The peer’s socket address.
Sourcepub async fn recv_event(&mut self) -> Result<Option<SrtEvent>>
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.
Sourcepub async fn recv(&mut self) -> Result<Option<Bytes>>
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.
Sourcepub fn next_damage(&mut self) -> Option<Damage>
pub fn next_damage(&mut self) -> Option<Damage>
The next damage report already received by a Self::recv call.
Sourcepub fn recv_buffer_size(&self) -> Result<usize>
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.
Sourcepub fn stats(&self) -> SocketStats
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.