sheave_core::net

Trait RtmpReadExt

Source
pub trait RtmpReadExt: AsyncRead {
    // Provided methods
    fn await_until_receiving<'a>(&'a mut self) -> AwaitUntilReceiving<'a, Self>
       where Self: Sized + Unpin { ... }
    fn try_read_after<'a>(
        &'a mut self,
        await_duration: Duration,
    ) -> TryReadAfter<'a, Self>
       where Self: Sized + Unpin { ... }
}
Expand description

Reader extensions for RTMP.

In almost cases, the network communication is enough just to await until receiving some message. But RTMP clients are required to be able to read messages both Acknowledgement and stream closing from servers, and these messages aren’t necessarily always sent. In this moment, clients will be stayed their processings if await receiving forever.

For solving above timing mismatches, to prepare several choices to receive chunks are required.

This trait provides several flexibility to read chunk by preparing following methods.

Provided Methods§

Source

fn await_until_receiving<'a>(&'a mut self) -> AwaitUntilReceiving<'a, Self>
where Self: Sized + Unpin,

Makes a stream awaiting until receiving some message.

§Examples
use tokio::io::{
    AsyncRead,
    AsyncReadExt,
    AsyncWrite,
    AsyncWriteExt
};
use sheave_core::{
    handlers::VecStream,
    net::RtmpReadExt
};

#[tokio::main]
async fn main() {
    let mut stream = VecStream::default();
    stream.write_u8(1).await.unwrap();
    assert!(stream.await_until_receiving().read_u8().await.is_ok())
}
Source

fn try_read_after<'a>( &'a mut self, await_duration: Duration, ) -> TryReadAfter<'a, Self>
where Self: Sized + Unpin,

Makes a stream sleeping during specified duration.

§Examples
use std::time::Duration;
use tokio::io::{
    AsyncRead,
    AsyncReadExt,
    AsyncWrite,
    AsyncWriteExt
};
use sheave_core::{
    handlers::VecStream,
    net::RtmpReadExt
};

#[tokio::main]
async fn main() {
    let mut stream = VecStream::default();
    stream.write_u8(1).await.unwrap();
    assert!(stream.try_read_after(Duration::from_secs(1)).read_u8().await.is_ok())
}

Implementors§

Source§

impl<R: AsyncRead> RtmpReadExt for R