Add hello example

This commit is contained in:
jD91mZM2
2018-06-02 18:19:55 +02:00
parent 6f362b4548
commit 31a2b95fe0
5 changed files with 44 additions and 22 deletions
+22
View File
@@ -0,0 +1,22 @@
extern crate syscall;
use std::{
fs::File,
io::{self, prelude::*},
os::unix::io::{AsRawFd, FromRawFd}
};
fn from_syscall_error(error: syscall::Error) -> io::Error {
io::Error::from_raw_os_error(error.errno as i32)
}
fn main() -> io::Result<()> {
let server = File::create("chan:hello")?;
loop {
let stream = syscall::dup(server.as_raw_fd(), b"listen").map_err(from_syscall_error)?;
let mut stream = unsafe { File::from_raw_fd(stream) };
stream.write(b"Hello World!\n")?;
}
}