Skip to content

Commit

Permalink
Merge pull request #10 from l0kod/feature/sigwinch
Browse files Browse the repository at this point in the history
Handle SIGWINCH, update std code and fix typos
  • Loading branch information
BurntSushi committed Oct 16, 2016
2 parents 50972e4 + a5e0567 commit 5ff5cd5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 31 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ in a separate thread) or for a signal to be delivered:
extern crate chan;
extern crate chan_signal;

use std::thread;
use std::time::Duration;

use chan_signal::Signal;

fn main() {
Expand All @@ -49,7 +52,7 @@ fn main() {
// When our work is complete, send a sentinel value on `sdone`.
let (sdone, rdone) = chan::sync(0);
// Run work.
::std::thread::spawn(move || run(sdone));
thread::spawn(move || run(sdone));

// Wait for a signal or for work to be done.
chan_select! {
Expand All @@ -66,7 +69,7 @@ fn run(_sdone: chan::Sender<()>) {
println!("Running work for 5 seconds.");
println!("Can you send a signal quickly enough?");
// Do some work.
::std::thread::sleep_ms(5000);
thread::sleep(Duration::from_secs(5));

// _sdone gets dropped which closes the channel and causes `rdone`
// to unblock.
Expand Down
7 changes: 5 additions & 2 deletions examples/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
extern crate chan;
extern crate chan_signal;

use std::thread;
use std::time::Duration;

use chan_signal::Signal;

fn main() {
Expand All @@ -10,7 +13,7 @@ fn main() {
// When our work is complete, send a sentinel value on `sdone`.
let (sdone, rdone) = chan::sync(0);
// Run work.
::std::thread::spawn(move || run(sdone));
thread::spawn(move || run(sdone));

// Wait for a signal or for work to be done.
chan_select! {
Expand All @@ -27,5 +30,5 @@ fn run(_sdone: chan::Sender<()>) {
println!("Running work for 5 seconds.");
println!("Can you send a signal quickly enough?");
// Do some work.
::std::thread::sleep_ms(5000);
thread::sleep(Duration::from_secs(5));
}
2 changes: 1 addition & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use chan_signal::{Signal, notify};

fn main() {
let signal = notify(&[Signal::INT]);
println!("Send a TERM signal my way!");
println!("Send a INT signal my way!");
// block until we get a signal
assert_eq!(signal.recv(), Some(Signal::INT));
println!("Thanks :]");
Expand Down
6 changes: 3 additions & 3 deletions examples/sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
extern crate chan_signal;

use std::thread;
use std::time::Duration;

use chan_signal::{Signal, notify};

fn main() {
let signal = notify(&[Signal::INT]);
println!("Send a TERM signal my way!");
thread::spawn(move || thread::sleep_ms(10000));
// thread::sleep_ms(5000);
println!("Send a INT signal my way!");
thread::spawn(move || thread::sleep(Duration::from_secs(10)));
// block until we get a signal
assert_eq!(signal.recv(), Some(Signal::INT));
println!("Thanks :]");
Expand Down
5 changes: 3 additions & 2 deletions examples/test_sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ extern crate chan;
extern crate chan_signal;

use std::thread;
use std::time::Duration;

use chan_signal::{Signal, kill_this};

fn main() {
let (s, r) = chan::sync(1);
chan_signal::notify_on(&s, Signal::HUP);
thread::spawn(move || thread::sleep_ms(10000));
thread::sleep_ms(500);
thread::spawn(move || thread::sleep(Duration::from_secs(10)));
thread::sleep(Duration::from_millis(500));
kill_this(Signal::HUP);
assert_eq!(r.recv(), Some(Signal::HUP));
}
23 changes: 2 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ use libc::{
// Common Extensions (SIGINFO and SIGEMT not in libc)
SIGIO,
SIGWINCH,

SIG_SETMASK,
};
use libc::kill;
use libc::getpid;
Expand Down Expand Up @@ -424,27 +426,6 @@ extern {

// Most of this was lifted out of rust-lang:rust/src/libstd/sys/unix/c.rs.

#[cfg(all(any(target_os = "linux", target_os = "android"),
any(target_arch = "x86",
target_arch = "x86_64",
target_arch = "powerpc",
target_arch = "arm",
target_arch = "aarch64")))]
const SIG_SETMASK: libc::c_int = 2;

#[cfg(all(any(target_os = "linux", target_os = "android"),
any(target_arch = "mips", target_arch = "mipsel")))]
const SIG_SETMASK: libc::c_int = 3;

#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "bitrig",
target_os = "netbsd",
target_os = "openbsd"))]
const SIG_SETMASK: libc::c_int = 3;

#[cfg(all(target_os = "linux", target_pointer_width = "32"))]
#[repr(C)]
struct sigset_t {
Expand Down

0 comments on commit 5ff5cd5

Please sign in to comment.