pub enum ProtocolError {
UnmaskedFrame,
MaskedFrame,
InvalidOpcode(u8),
InvalidLength(usize),
BadOpCode,
Overflow,
ContinuationNotStarted,
ContinuationStarted,
ContinuationFragment(OpCode),
SendClosed,
RecvClosed,
UnexpectedEof,
}Expand description
WebSocket protocol errors.
§Close handshake errors
SendClosed, RecvClosed, and
UnexpectedEof are related to the WebSocket close handshake.
Their meaning depends on the context in which they are observed:
§SendClosed
Returned by [ResponseSender::send] when a Close frame has already been sent on this
session. This can happen in two scenarios:
- You called
close()and then tried to send more messages. After sending a Close frame, no further messages are permitted per RFC 6455. - A concurrent sender (via [
ResponseWeakSender::upgrade]) already initiated the close. The caller observing this error should return gracefully — the shutdown is already in progress.
§RecvClosed
Returned by [RequestStream] (as WsError::Protocol(ProtocolError::RecvClosed)) when
the stream is polled after a Close frame has already been received and yielded. The
caller should have stopped polling after observing Message::Close. Receiving this
error means:
- The remote peer sent a Close frame, which was already yielded as
Ok(Message::Close(_)). - The caller should respond with a Close frame via [
ResponseSender] (if not already sent) and then drop both the stream and sender.
§UnexpectedEof
Returned by [RequestStream] when the underlying transport closed without a Close
frame. This is an abnormal closure — the remote peer disconnected without following the
WebSocket protocol. The associated connection should not be reused.
§Typical close flows
Remote-initiated close:
- [
RequestStream] yieldsOk(Message::Close(reason)). - Caller sends a Close frame back via [
ResponseSender::close]. - Caller drops both the stream and sender.
Local-initiated close:
- Caller calls [
ResponseSender::close]. - Caller continues polling [
RequestStream] for the peer’s Close echo. - [
RequestStream] yieldsOk(Message::Close(_))— handshake complete. - Caller drops the stream. Any concurrent senders attempting to send will observe
SendClosed.
Timeout on close echo:
- Caller calls [
ResponseSender::close]. - Caller polls [
RequestStream] with a timeout. - Timeout expires — caller sends an error via [
ResponseSender::send_error] to signal the I/O layer to shut down the connection.
Variants§
UnmaskedFrame
MaskedFrame
InvalidOpcode(u8)
InvalidLength(usize)
BadOpCode
Overflow
ContinuationNotStarted
ContinuationStarted
ContinuationFragment(OpCode)
SendClosed
A Close frame has already been sent. No further messages can be sent.
RecvClosed
A Close frame has already been received. The caller should stop polling the stream.
UnexpectedEof
The underlying transport closed without a Close frame. This is an abnormal closure.
Trait Implementations§
Source§impl Debug for ProtocolError
impl Debug for ProtocolError
Source§impl Display for ProtocolError
impl Display for ProtocolError
Source§impl Error for ProtocolError
impl Error for ProtocolError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()