mirror of
https://github.com/openharmony/third_party_rust_signal-hook.git
synced 2026-07-01 20:44:18 -04:00
Async crates improvements
* Make the streams for _all_ variants of SignalsInfo * Remove unnecessary parts of examples
This commit is contained in:
@@ -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 => {
|
||||
@@ -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),
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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 => {
|
||||
@@ -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);
|
||||
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user