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

Loading…
Cancel
Save