@@ -328,7 +328,7 @@ where
328
328
fn start_send ( mut self : Pin < & mut Self > , item : Message ) -> Result < ( ) , Self :: Error > {
329
329
match ( * self ) . with_context ( None , |s| s. write_message ( item) ) {
330
330
Ok ( ( ) ) => Ok ( ( ) ) ,
331
- Err ( :: tungstenite :: Error :: Io ( err) ) if err. kind ( ) == std:: io:: ErrorKind :: WouldBlock => {
331
+ Err ( WsError :: Io ( err) ) if err. kind ( ) == std:: io:: ErrorKind :: WouldBlock => {
332
332
// the message was accepted and queued
333
333
// isn't an error.
334
334
Ok ( ( ) )
@@ -341,7 +341,19 @@ where
341
341
}
342
342
343
343
fn poll_flush ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > > {
344
- ( * self ) . with_context ( Some ( ( ContextWaker :: Write , cx) ) , |s| cvt ( s. write_pending ( ) ) )
344
+ match ( * self ) . with_context ( Some ( ( ContextWaker :: Write , cx) ) , |s| s. write_pending ( ) ) {
345
+ Ok ( ( ) ) => Poll :: Ready ( Ok ( ( ) ) ) ,
346
+ Err ( WsError :: ConnectionClosed ) => {
347
+ // WebSocket is closing and there is nothing to send anymore.
348
+ // Not an failure, the flush operation is a success.
349
+ Poll :: Ready ( Ok ( ( ) ) )
350
+ }
351
+ Err ( WsError :: Io ( ref e) ) if e. kind ( ) == std:: io:: ErrorKind :: WouldBlock => {
352
+ trace ! ( "WouldBlock" ) ;
353
+ Poll :: Pending
354
+ }
355
+ Err ( e) => Poll :: Ready ( Err ( e) ) ,
356
+ }
345
357
}
346
358
347
359
fn poll_close ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , Self :: Error > > {
@@ -354,8 +366,8 @@ where
354
366
355
367
match res {
356
368
Ok ( ( ) ) => Poll :: Ready ( Ok ( ( ) ) ) ,
357
- Err ( :: tungstenite :: Error :: ConnectionClosed ) => Poll :: Ready ( Ok ( ( ) ) ) ,
358
- Err ( :: tungstenite :: Error :: Io ( err) ) if err. kind ( ) == std:: io:: ErrorKind :: WouldBlock => {
369
+ Err ( WsError :: ConnectionClosed ) => Poll :: Ready ( Ok ( ( ) ) ) ,
370
+ Err ( WsError :: Io ( err) ) if err. kind ( ) == std:: io:: ErrorKind :: WouldBlock => {
359
371
trace ! ( "WouldBlock" ) ;
360
372
self . closing = true ;
361
373
Poll :: Pending
0 commit comments