Skip to content

Commit

Permalink
Merge pull request #129 from vorner/defuse
Browse files Browse the repository at this point in the history
Async crates improvements
  • Loading branch information
vorner authored Jan 8, 2022
2 parents 205d686 + 8dfe750 commit 3272196
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
9 changes: 4 additions & 5 deletions signal-hook-async-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
//! use signal_hook::consts::signal::*;
//! use signal_hook_async_std::Signals;
//!
//! async fn handle_signals(signals: Signals) {
//! let mut signals = signals.fuse();
//! async fn handle_signals(mut signals: Signals) {
//! while let Some(signal) = signals.next().await {
//! match signal {
//! SIGHUP => {
Expand Down Expand Up @@ -106,7 +105,7 @@ impl<E: Exfiltrator> SignalsInfo<E> {
}
}

impl SignalsInfo {
impl<E: Exfiltrator> SignalsInfo<E> {
fn has_signals(read: &mut Async<UnixStream>, ctx: &mut Context<'_>) -> Result<bool, Error> {
match Pin::new(read).poll_read(ctx, &mut [0u8]) {
Poll::Pending => Ok(false),
Expand All @@ -116,8 +115,8 @@ impl SignalsInfo {
}
}

impl Stream for SignalsInfo {
type Item = c_int;
impl<E: Exfiltrator> Stream for SignalsInfo<E> {
type Item = E::Output;

fn poll_next(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
match self.0.poll_signal(&mut |read| Self::has_signals(read, ctx)) {
Expand Down
9 changes: 4 additions & 5 deletions signal-hook-tokio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
//!
//! use futures::stream::StreamExt;
//!
//! async fn handle_signals(signals: Signals) {
//! let mut signals = signals.fuse();
//! async fn handle_signals(mut signals: Signals) {
//! while let Some(signal) = signals.next().await {
//! match signal {
//! SIGHUP => {
Expand Down Expand Up @@ -131,7 +130,7 @@ impl<E: Exfiltrator> SignalsInfo<E> {
/// information.
pub type Signals = SignalsInfo<SignalOnly>;

impl Signals {
impl<E: Exfiltrator> SignalsInfo<E> {
fn has_signals(read: &mut UnixStream, ctx: &mut Context<'_>) -> Result<bool, Error> {
let mut buf = [0u8];
let mut read_buf = ReadBuf::new(&mut buf);
Expand All @@ -145,8 +144,8 @@ impl Signals {

#[cfg_attr(docsrs, doc(cfg(feature = "futures-v0_3")))]
#[cfg(feature = "futures-v0_3")]
impl Stream for Signals {
type Item = c_int;
impl<E: Exfiltrator> Stream for SignalsInfo<E> {
type Item = E::Output;

fn poll_next(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
match self.0.poll_signal(&mut |read| Self::has_signals(read, ctx)) {
Expand Down

0 comments on commit 3272196

Please sign in to comment.