Split unsafe block HttpServiceHandlerResponse

Also add explanation of the safety of the usage of `unsafe`
This commit is contained in:
Aaron Hill 2019-07-09 21:08:11 -04:00
parent 50397fb63b
commit 68bb76beec
No known key found for this signature in database
GPG Key ID: B4087E510E98B164
1 changed files with 12 additions and 10 deletions

View File

@ -466,18 +466,20 @@ where
State::Unknown(ref mut data) => {
if let Some(ref mut item) = data {
loop {
unsafe {
let b = item.1.bytes_mut();
// Safety - we only write to the returned slice.
let b = unsafe { item.1.bytes_mut() };
let n = try_ready!(item.0.poll_read(b));
if n == 0 {
return Ok(Async::Ready(()));
}
item.1.advance_mut(n);
// Safety - we know that 'n' bytes have
// been initialized via the contract of
// 'poll_read'
unsafe { item.1.advance_mut(n) };
if item.1.len() >= HTTP2_PREFACE.len() {
break;
}
}
}
} else {
panic!()
}