@@ -507,11 +507,6 @@ impl WebSocket {
507507 . map_err ( Error :: new)
508508 }
509509
510- /// Gracefully close this WebSocket.
511- pub async fn close ( mut self ) -> Result < ( ) , Error > {
512- self . inner . close ( None ) . await . map_err ( Error :: new)
513- }
514-
515510 /// Return the selected WebSocket subprotocol, if one has been chosen.
516511 pub fn protocol ( & self ) -> Option < & HeaderValue > {
517512 self . protocol . as_ref ( )
@@ -615,6 +610,24 @@ pub enum Message {
615610 /// [unidirectional heartbeat](https://tools.ietf.org/html/rfc6455#section-5.5.3).
616611 Pong ( Vec < u8 > ) ,
617612 /// A close message with the optional close frame.
613+ ///
614+ /// You may "uncleanly" close a WebSocket connection at any time
615+ /// by simply dropping the [`WebSocket`].
616+ /// However, you may also use the graceful closing protocol, in which
617+ /// 1. peer A sends a close frame, and does not send any further messages;
618+ /// 2. peer B responds with a close frame, and does not send any further messages;
619+ /// 3. peer A processes the remaining messages sent by peer B, before finally
620+ /// 4. both peers close the connection.
621+ ///
622+ /// After sending a close frame,
623+ /// you may still read messages,
624+ /// but attempts to send another message will error.
625+ /// After receiving a close frame,
626+ /// axum will automatically respond with a close frame if necessary
627+ /// (you do not have to deal with this yourself).
628+ /// Since no further messages will be received,
629+ /// you may either do nothing
630+ /// or explicitly drop the connection.
618631 Close ( Option < CloseFrame < ' static > > ) ,
619632}
620633
0 commit comments