Skip to content

Commit

Permalink
fix: High CPU Usage (100%) in Specific Scenarios, better version (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
leibeiyi committed Jun 3, 2024
1 parent 15df34b commit c0f5c8e
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/codec/framed_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,27 @@ where

loop {
while !self.encoder.is_empty() {
match self.encoder.next {
let n = match self.encoder.next {
Some(Next::Data(ref mut frame)) => {
tracing::trace!(queued_data_frame = true);
let mut buf = (&mut self.encoder.buf).chain(frame.payload_mut());
ready!(poll_write_buf(Pin::new(&mut self.inner), cx, &mut buf))?
}
_ => {
tracing::trace!(queued_data_frame = false);
let n = ready!(poll_write_buf(
ready!(poll_write_buf(
Pin::new(&mut self.inner),
cx,
&mut self.encoder.buf
))?;
if n == 0 {
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::WriteZero,
"failed to write frame to socket",
)));
}
n
))?
}
};
if n == 0 {
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::WriteZero,
"failed to write frame to socket",
)));
}
}

match self.encoder.unset_frame() {
Expand Down

0 comments on commit c0f5c8e

Please sign in to comment.