fcntl(fd, F_SETFL, O_NONBLOCK)
extern crate libc;
use std::{thread, time};
fn main() {
println!("Hello, world!");
unsafe {
libc::fcntl(0, libc::F_SETFL, libc::O_NONBLOCK);
}
let mut buf:[libc::c_char;1] = [0;1];
let mut ptr = &mut buf;
loop {
unsafe {
let r = libc::read(0, ptr.as_ptr() as *mut libc::c_void, 1);
if r > 0 {
println!("input !{:?}",*ptr);
break;
}
thread::sleep(time::Duration::from_millis(100));
}
}
}