1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-22 05:35:08 +02:00

optimize websocket stream

This commit is contained in:
Nikolay Kim
2018-03-08 17:19:50 -08:00
parent 395243a539
commit ebdc983dfe
7 changed files with 123 additions and 37 deletions

View File

@@ -122,14 +122,21 @@ impl Frame {
None
};
let mut data = match pl.readexactly(idx + length)? {
Async::Ready(Some(buf)) => buf,
match pl.can_read(idx + length)? {
Async::Ready(Some(true)) => (),
Async::Ready(None) => return Ok(Async::Ready(None)),
Async::NotReady => return Ok(Async::NotReady),
};
Async::Ready(Some(false)) | Async::NotReady => return Ok(Async::NotReady),
}
// remove prefix
pl.drop_payload(idx);
// get body
data.split_to(idx);
let data = match pl.readexactly(length)? {
Async::Ready(Some(buf)) => buf,
Async::Ready(None) => return Ok(Async::Ready(None)),
Async::NotReady => panic!(),
};
// Disallow bad opcode
if let OpCode::Bad = opcode {
@@ -150,7 +157,9 @@ impl Frame {
// unmask
if let Some(ref mask) = mask {
apply_mask(&mut data, mask);
#[allow(mutable_transmutes)]
let p: &mut [u8] = unsafe{let ptr: &[u8] = &data; mem::transmute(ptr)};
apply_mask(p, mask);
}
Ok(Async::Ready(Some(Frame {