pub struct CloseHandshake { /* private fields */ }Expand description
Close handshake state machine.
Tracks the state of the WebSocket close handshake and provides methods for transitioning through the handshake phases.
Implementations§
Source§impl CloseHandshake
impl CloseHandshake
Sourcepub fn with_config(config: CloseConfig) -> Self
pub fn with_config(config: CloseConfig) -> Self
Create with custom configuration.
Sourcepub const fn state(&self) -> CloseState
pub const fn state(&self) -> CloseState
Get the current state.
Sourcepub fn our_reason(&self) -> Option<&CloseReason>
pub fn our_reason(&self) -> Option<&CloseReason>
Get our close reason (if we initiated).
Sourcepub fn peer_reason(&self) -> Option<&CloseReason>
pub fn peer_reason(&self) -> Option<&CloseReason>
Get peer’s close reason (if they initiated).
Sourcepub const fn close_timeout(&self) -> Duration
pub const fn close_timeout(&self) -> Duration
Get the close timeout.
Sourcepub fn initiate(&mut self, reason: CloseReason) -> Option<Frame>
pub fn initiate(&mut self, reason: CloseReason) -> Option<Frame>
Initiate a close handshake.
Returns the close frame to send, or None if already closing/closed.
§State Transitions
Open→CloseSent: Returns close frameCloseReceived→Closed: Returns close frame (response)CloseSent|Closed: ReturnsNone
Sourcepub fn receive_close(&mut self, frame: &Frame) -> Result<Option<Frame>, WsError>
pub fn receive_close(&mut self, frame: &Frame) -> Result<Option<Frame>, WsError>
Handle a received close frame.
Returns the close frame to send in response, or None if no response needed.
§State Transitions
Open→CloseReceived: Stores peer reason, returns response frameCloseSent→Closed: Stores peer reason, returnsNone(handshake complete)CloseReceived|Closed: ReturnsNone(duplicate/unexpected)
Sourcepub fn force_close(&mut self, reason: CloseReason)
pub fn force_close(&mut self, reason: CloseReason)
Force transition to closed state.
Use this when the connection is terminated without proper handshake (timeout, error, etc.).
Trait Implementations§
Source§impl Debug for CloseHandshake
impl Debug for CloseHandshake
Auto Trait Implementations§
impl Freeze for CloseHandshake
impl RefUnwindSafe for CloseHandshake
impl Send for CloseHandshake
impl Sync for CloseHandshake
impl Unpin for CloseHandshake
impl UnsafeUnpin for CloseHandshake
impl UnwindSafe for CloseHandshake
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).