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.
await_until_receiving
: The default of receiving behavior.try_read_after
: Currently for clients.
Provided Methods§
Sourcefn await_until_receiving<'a>(&'a mut self) -> AwaitUntilReceiving<'a, Self>
fn await_until_receiving<'a>(&'a mut self) -> AwaitUntilReceiving<'a, Self>
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())
}
Sourcefn try_read_after<'a>(
&'a mut self,
await_duration: Duration,
) -> TryReadAfter<'a, Self>
fn try_read_after<'a>( &'a mut self, await_duration: Duration, ) -> TryReadAfter<'a, Self>
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())
}