@@ -12,7 +12,7 @@ use std::{
1212use tokio:: net:: TcpStream ;
1313use tokio_tungstenite:: {
1414 connect_async,
15- tungstenite:: { Bytes , Error , Message } ,
15+ tungstenite:: { protocol :: CloseFrame , Bytes , Error , Message } ,
1616 MaybeTlsStream , WebSocketStream ,
1717} ;
1818use tracing:: debug;
@@ -88,11 +88,11 @@ where
8888 }
8989 }
9090
91- while let State :: Stream ( pong ) = & mut this. state {
92- if pong . is_some ( ) {
91+ while let State :: Stream ( msg ) = & mut this. state {
92+ if msg . is_some ( ) {
9393 let mut sink = Pin :: new ( this. sink . as_mut ( ) . unwrap ( ) ) ;
9494 let _ = ready ! ( sink. as_mut( ) . poll_ready( cx) ) ;
95- if let Some ( pong) = pong . take ( ) {
95+ if let Some ( pong) = msg . take ( ) {
9696 let _ = sink. as_mut ( ) . start_send ( pong) ;
9797 }
9898 let _ = ready ! ( sink. as_mut( ) . poll_flush( cx) ) ;
@@ -115,6 +115,7 @@ where
115115 return Poll :: Ready ( Some ( FlashBlock :: decode ( bytes. into ( ) ) ) )
116116 }
117117 Ok ( Message :: Ping ( bytes) ) => this. ping ( bytes) ,
118+ Ok ( Message :: Close ( frame) ) => this. close ( frame) ,
118119 Ok ( msg) => debug ! ( "Received unexpected message: {:?}" , msg) ,
119120 Err ( err) => return Poll :: Ready ( Some ( Err ( err. into ( ) ) ) ) ,
120121 }
@@ -148,6 +149,12 @@ where
148149 current. replace ( Message :: Pong ( pong) ) ;
149150 }
150151 }
152+
153+ fn close ( & mut self , frame : Option < CloseFrame > ) {
154+ if let State :: Stream ( current) = & mut self . state {
155+ current. replace ( Message :: Close ( frame) ) ;
156+ }
157+ }
151158}
152159
153160impl < Stream : Debug , S : Debug , C : Debug > Debug for WsFlashBlockStream < Stream , S , C > {
0 commit comments