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,
ca_file: Option<&str>,
insecure: bool,
) -> Result<Self>
pub fn connect_tls( stream: TcpStream, host: &str, ca_file: Option<&str>, insecure: bool, ) -> Result<Self>
Perform a blocking TLS client handshake over an already-connected
stream (RTMPS). By default validates the server certificate against
the system trust store and checks host against the certificate (SNI
- hostname verification), matching standard TLS client behavior.
ca_file(PEM bundle): verification trusts only the CAs in this bundle, replacing the system trust store rather than adding to it — so a caller pinning a private CA doesn’t also accept publicly trusted certificates for the same hostname.insecure = true: skip certificate verification entirely (only for testing against self-signed deployments; never use in production). The system default verify paths are never touched in this mode, so a host with no usable default CA store still connects.
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). Uses a fixed default
timeout; call Transport::connect_tls_with_timeout to bound it by
an existing deadline instead.
Sourcepub fn connect_tls_with_timeout(
stream: TcpStream,
host: &str,
ca_file: Option<&str>,
insecure: bool,
timeout: Duration,
) -> Result<Self>
pub fn connect_tls_with_timeout( stream: TcpStream, host: &str, ca_file: Option<&str>, insecure: bool, timeout: Duration, ) -> Result<Self>
Same as Transport::connect_tls, but timeout bounds the whole
handshake instead of the fixed default. Pass the caller’s remaining
connect deadline here — otherwise the TLS handshake could run well
past the overall connect timeout the caller already spent on DNS/TCP
connect.
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.