summaryrefslogtreecommitdiffstats
path: root/tokio/src/signal
diff options
context:
space:
mode:
authorSean McArthur <sean@seanmonstar.com>2020-08-13 20:15:01 -0700
committerGitHub <noreply@github.com>2020-08-13 20:15:01 -0700
commitc393236dfd12c13e82badd631d3a3a90481c6f95 (patch)
tree47e7e70b7a58fb968870d5d44e95f6c45192e114 /tokio/src/signal
parent71da06097bf9aa851ebdde79d7b01a3e38174db9 (diff)
io: change AsyncRead to use a ReadBuf (#2758)
Works towards #2716. Changes the argument to `AsyncRead::poll_read` to take a `ReadBuf` struct that safely manages writes to uninitialized memory.
Diffstat (limited to 'tokio/src/signal')
-rw-r--r--tokio/src/signal/unix.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/tokio/src/signal/unix.rs b/tokio/src/signal/unix.rs
index b46b15c9..bc48bdfa 100644
--- a/tokio/src/signal/unix.rs
+++ b/tokio/src/signal/unix.rs
@@ -5,7 +5,7 @@
#![cfg(unix)]
-use crate::io::{AsyncRead, PollEvented};
+use crate::io::{AsyncRead, PollEvented, ReadBuf};
use crate::signal::registry::{globals, EventId, EventInfo, Globals, Init, Storage};
use crate::sync::mpsc::{channel, Receiver};
@@ -300,10 +300,16 @@ impl Driver {
/// [#38](https://github.com/alexcrichton/tokio-signal/issues/38) for more
/// info.
fn drain(&mut self, cx: &mut Context<'_>) {
+ let mut buf = [0; 128];
+ let mut buf = ReadBuf::new(&mut buf);
loop {
- match Pin::new(&mut self.wakeup).poll_read(cx, &mut [0; 128]) {
- Poll::Ready(Ok(0)) => panic!("EOF on self-pipe"),
- Poll::Ready(Ok(_)) => {}
+ match Pin::new(&mut self.wakeup).poll_read(cx, &mut buf) {
+ Poll::Ready(Ok(())) => {
+ if buf.filled().is_empty() {
+ panic!("EOF on self-pipe")
+ }
+ buf.clear();
+ }
Poll::Ready(Err(e)) => panic!("Bad read on self-pipe: {}", e),
Poll::Pending => break,
}