Skip to content

Commit f4a8595

Browse files
authored
Merge pull request #152 from vaptu/master
feat: add rtmp client session timeout option
2 parents dffca6e + 68e4655 commit f4a8595

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

protocol/rtmp/src/session/client_session.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use {
2727
},
2828
indexmap::IndexMap,
2929
std::sync::Arc,
30+
std::time::Duration,
3031
//crate::utils::print::print,
3132
streamhub::define::StreamHubEventSender,
3233
tokio::{net::TcpStream, sync::Mutex},
@@ -67,6 +68,7 @@ pub enum ClientSessionType {
6768
}
6869
pub struct ClientSession {
6970
io: Arc<Mutex<Box<dyn TNetIO + Send + Sync>>>,
71+
timeout: Option<Duration>,
7072
common: Common,
7173
handshaker: SimpleHandshakeClient,
7274
unpacketizer: ChunkUnpacketizer,
@@ -115,6 +117,7 @@ impl ClientSession {
115117

116118
Self {
117119
io: Arc::clone(&net_io),
120+
timeout: None,
118121
common,
119122
handshaker: SimpleHandshakeClient::new(Arc::clone(&net_io)),
120123
unpacketizer: ChunkUnpacketizer::new(),
@@ -129,6 +132,10 @@ impl ClientSession {
129132
gop_num,
130133
}
131134
}
135+
136+
pub fn set_timeout(&mut self, timeout: Duration){
137+
self.timeout = Some(timeout)
138+
}
132139

133140
pub async fn run(&mut self) -> Result<(), SessionError> {
134141
loop {
@@ -169,7 +176,10 @@ impl ClientSession {
169176
ClientSessionState::WaitStateChange => {}
170177
}
171178

172-
let data = self.io.lock().await.read().await?;
179+
let data = match self.timeout {
180+
None => self.io.lock().await.read().await?,
181+
Some(t) => self.io.lock().await.read_timeout(t).await?,
182+
};
173183
self.unpacketizer.extend_data(&data[..]);
174184

175185
loop {

0 commit comments

Comments
 (0)