Skip to content

Commit

Permalink
Merge pull request #454 from weibocom/dev_handler_hotfix
Browse files Browse the repository at this point in the history
handler hot fix: 使用req_buf时,会导致数据发送到stream中逆序
  • Loading branch information
viciousstar authored Apr 18, 2024
2 parents e5a1998 + 6042381 commit a5fe8cb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion stream/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,19 @@ where
fn poll_request(&mut self, cx: &mut Context) -> Poll<Result<()>> {
while ready!(self.data.poll_recv_many(cx, &mut self.req_buf, 4)) > 0 {
self.s.cache(self.req_buf.len() > 1);
while let Some(req) = self.req_buf.pop() {
let ptr = self.req_buf.as_ptr();
for i in 0..self.req_buf.len() {
let req = unsafe { ptr.add(i).read() };
self.s.write_slice(&*req, 0).expect("should not err");
self.num.tx();
match req.on_sent() {
Some(r) => self.pending.push_back((r, Instant::now())),
None => self.num.rx(),
}
}
// 发送完成后,清空buffer
// 在这是安全的,因为在L110已经读取所有数据,并且这当中不会中断
unsafe { self.req_buf.set_len(0) };
}
Poll::Ready(Err(Error::ChanReadClosed))
}
Expand Down

0 comments on commit a5fe8cb

Please sign in to comment.