pub struct Transport { /* private fields */ }Expand description
Transport wraps a connected socket fd and presents a single send/recv API.
The transport OWNS the file descriptor: it is closed when the transport
is dropped (plain: explicit close(2); TLS: via TcpStream drop inside
the SSL stream).
Implementations§
Source§impl Transport
impl Transport
Sourcepub fn connect_tls(stream: TcpStream, host: &str) -> Result<Self>
pub fn connect_tls(stream: TcpStream, host: &str) -> Result<Self>
Perform a blocking TLS client handshake over an already-connected
stream (RTMPS). Validates the server certificate against the system
trust store and checks host against the certificate (SNI + hostname
verification), matching standard TLS client behavior.
stream must not already be set non-blocking; this performs a
synchronous handshake, matching Client’s
otherwise-blocking connect sequence. The handshake itself is bounded by
a read/write timeout so a peer that completes the TCP connect but then
stalls mid-handshake cannot hang the caller indefinitely (mirroring the
bound send() places on writes post-handshake).
Sourcepub fn fd(&self) -> i32
pub fn fd(&self) -> i32
Return the underlying file descriptor (used for poll(2) and as a
connection identifier; I/O is performed through this struct).
Sourcepub fn recv(&mut self, buf: &mut [u8], again: &mut i32) -> isize
pub fn recv(&mut self, buf: &mut [u8], again: &mut i32) -> isize
Non-blocking receive.
Returns the number of bytes read (>0), 0 on clean peer shutdown, or -1
on error. On -1, again indicates a transient would-block:
1 = wait for readable (EAGAIN / TLS WANT_READ)
2 = wait for writable (TLS WANT_WRITE during a read)
0 = fatal error.
Sourcepub fn try_send(&mut self, data: &[u8], again: &mut i32) -> Result<usize>
pub fn try_send(&mut self, data: &[u8], again: &mut i32) -> Result<usize>
Non-blocking send. Returns bytes written, or 0 when the socket is not
ready. On Ok(0), again is set to indicate the poll direction:
1 = wait for readable (TLS WANT_READ during write, e.g. renegotiation)
2 = wait for writable (EAGAIN/EWOULDBLOCK/EINTR/TLS WANT_WRITE)
Used by the server poll loop so one slow peer cannot stall all connections.
Sourcepub fn send(&mut self, data: &[u8]) -> Result<()>
pub fn send(&mut self, data: &[u8]) -> Result<()>
Blocking send of the whole buffer (client-side synchronous I/O).
Uses a 10-second poll timeout rather than an infinite wait so a peer that stops reading cannot block the caller indefinitely. Correctly handles TLS WANT_READ during writes (e.g. renegotiation) by polling for read readiness instead of write readiness.
Sourcepub fn pending(&self) -> i32
pub fn pending(&self) -> i32
Number of decrypted bytes already buffered inside the transport (always
0 for plaintext). For TLS, SSL_pending() reports application data
OpenSSL has already decrypted but the caller hasn’t read yet – data a
poll(2) readiness check on the raw fd cannot see, since the kernel
socket buffer it was decrypted from may already be empty.