Skip to content

Conversation

@Kumassy
Copy link
Owner

@Kumassy Kumassy commented Aug 16, 2025

This pull request refactors how the WebSocket sink (ws_tx) is managed in the Client struct to improve connection state handling and error management. The changes ensure that the sink is only available when the client is connected, and better handle cases where the connection is lost or needs to be re-established.

Connection state and sink management:

  • Changed the ws_tx field in the Client struct from a direct SplitSink to an Option<SplitSink>, allowing it to be explicitly set to None when the client is disconnected.
  • Updated the client constructor to initialize ws_tx as Some(sink), reflecting the new optional type.
  • Modified the set_wait_reconnect method to set ws_tx to None when the client transitions out of the connected state, ensuring the sink is dropped when the client disconnects.

Error handling and packet transmission:

  • Refactored the send_to_client method to check if ws_tx is None and return a ClientNotConnected error if so, improving error handling when trying to send data to a disconnected client.

Message decoding improvements:

  • Simplified message decoding by directly creating a BytesMut from the message's bytes, removing an unnecessary intermediate variable. [1] [2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants