@@ -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