Skip to main content

Transport

Struct Transport 

Source
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

Source

pub fn new_plain(fd: i32) -> Self

Wrap an owned fd as a plaintext transport.

Source

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).

Source

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).

Source

pub fn is_tls(&self) -> bool

Check if this transport uses TLS.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Drop for Transport

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§

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, 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.