Skip to content

Commit 27b062a

Browse files
committed
feat: tunnel keep-alive messages
1 parent 7630845 commit 27b062a

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/servers/tunnel.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,29 @@ impl Tunnel {
226226
return Poll::Ready(TunnelReadState::Stop);
227227
};
228228

229+
if message.index == 255 {
230+
// Write a ping response if we aren't already writing another message
231+
if let TunnelWriteState::Recv = self.write_state {
232+
// Move to a writing state
233+
self.write_state = TunnelWriteState::Write(Some(TunnelMessage {
234+
index: 255,
235+
message: Bytes::new(),
236+
}));
237+
238+
// Poll the write state
239+
if let Poll::Ready(next_state) = self.poll_write_state(cx) {
240+
self.write_state = next_state;
241+
242+
// Tunnel has stopped
243+
if let TunnelWriteState::Stop = self.write_state {
244+
return Poll::Ready(TunnelReadState::Stop);
245+
}
246+
}
247+
}
248+
249+
return Poll::Ready(TunnelReadState::Continue);
250+
}
251+
229252
// Get the handle to use within the connection pool
230253
let handle = self.pool.get(message.index as usize);
231254

@@ -491,6 +514,13 @@ mod codec {
491514
//! Length: 16-bits. Determines the size in bytes of the payload that follows
492515
//!
493516
//! Payload: Variable length. The message bytes payload of `Length`
517+
//!
518+
//!
519+
//! ## Keep alive
520+
//!
521+
//! The server will send keep-alive messages, these are in the same
522+
//! format as the packet above. However, the index will always be 255
523+
//! and the payload will be empty.
494524
495525
use bytes::{Buf, BufMut, Bytes};
496526
use tokio_util::codec::{Decoder, Encoder};

0 commit comments

Comments
 (0)