Skip to content

Commit 3a1901e

Browse files
committed
feat(error): added WriteError::ConnectionClosed
Signed-off-by: Jad K. Haddad <jadkhaddad@gmail.com>
1 parent f956b3a commit 3a1901e

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ pub enum ReadError<I> {
8585

8686
#[derive(Debug, thiserror::Error)]
8787
pub enum WriteError<I> {
88+
#[error("Connection closed")]
89+
ConnectionClosed,
8890
#[error("Write frame error: {0}")]
8991
WriteFrame(
9092
#[source]

src/websocket_core.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ impl Auto {
6868
pub struct ConnectionState {
6969
/// If the user sends a close frame, we should not send a close frame back.
7070
///
71-
/// Must be set to `true` if the user sends a close frame.
71+
/// Must be set to `true` if the user sends a close frame or the other side sends a close frame.
72+
///
73+
/// If the connection is closed, every read will return `None` and every write will return a [`WriteError::ConnectionClosed`].
7274
pub closed: bool,
7375
/// Auto handling of ping/pong and close frames.
7476
auto: Auto,
7577
}
7678

77-
// TODO: add a new write error: ConnectionClosed. closed must be set to true if the user sends a close frame, if the reader read a close frame.
78-
// Then the closed field must be set to true. Every read will then return (None, means connection closed) and every write will return a write error with ConnectionClosed.
79-
// And then add the tests for that. If the user closes the connection or the server closed the connection, and then the user tries to read or write a frame
79+
// TODO: Set ConnectionState.closed to true if the user sends a close frame or the other side sends a close frame.
80+
// TODO: If ConnectionState.closed: Every read will then return (None, means connection closed) and every write will return a write error with ConnectionClosed.
81+
// TODO: And then add the tests for that. If the user closes the connection or the server closed the connection, and then the user tries to read or write a frame
8082

8183
impl ConnectionState {
8284
#[inline]

0 commit comments

Comments
 (0)