
* Rewriting network functions * Add buffer to dup Fix non-blocking handling by triggering once on enabling events to read to EOF * Modifications for UDP API * Implement TCP client side * Add active close * Add DMAR parser * Implement basic TCP listening. Need to improve the state machine * Reduce debugging * Fixes for close procedure * Updates to fix path processing in libstd
40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
extern crate syscall;
|
|
|
|
use std::fs::File;
|
|
use std::io::{Read, Write};
|
|
use std::str;
|
|
use std::thread;
|
|
|
|
use syscall::{Packet, Result, Scheme};
|
|
|
|
struct ExampleScheme;
|
|
|
|
impl Scheme for ExampleScheme {
|
|
fn open(&self, path: &[u8], _flags: usize, uid: u32, gid: u32) -> Result<usize> {
|
|
println!("{} from {}:{}", unsafe { str::from_utf8_unchecked(path) }, uid, gid);
|
|
Ok(0)
|
|
}
|
|
|
|
fn dup(&self, file: usize, _buf: &[u8]) -> Result<usize> {
|
|
Ok(file)
|
|
}
|
|
|
|
fn close(&self, _file: usize) -> Result<usize> {
|
|
Ok(0)
|
|
}
|
|
}
|
|
|
|
fn main(){
|
|
thread::spawn(move || {
|
|
let mut socket = File::create(":example").expect("example: failed to create example scheme");
|
|
let scheme = ExampleScheme;
|
|
loop {
|
|
let mut packet = Packet::default();
|
|
socket.read(&mut packet).expect("example: failed to read events from example scheme");
|
|
println!("{:?}", packet);
|
|
scheme.handle(&mut packet);
|
|
socket.write(&packet).expect("example: failed to write responses to example scheme");
|
|
}
|
|
});
|
|
}
|