Refactor additional_send writing

pull/357/head
Alex Butler 2 years ago
parent 84a54b76e6
commit 06e55a4ef2
  1. 11
      src/protocol/mod.rs

@ -434,16 +434,17 @@ impl WebSocketContext {
// respond with Pong frame as soon as is practical. (RFC 6455)
let should_flush = if let Some(msg) = self.additional_send.take() {
trace!("Sending pong/close");
if let Err(err) = self.write_one_frame(stream, msg) {
match err {
match self.write_one_frame(stream, msg) {
Err(Error::WriteBufferFull(Message::Frame(msg))) => {
// if an system message would exceed the buffer put it back in
// `additional_send` for retry. Otherwise returning this error
// may not make sense to the user, e.g. calling `flush`.
Error::WriteBufferFull(Message::Frame(msg)) => self.set_additional(msg),
err => return Err(err),
self.set_additional(msg);
false
}
Err(err) => return Err(err),
Ok(_) => true,
}
true
} else {
false
};

Loading…
Cancel
Save