Redo networking (#22)
* 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
This commit is contained in:
parent
268c859fd6
commit
2491e4771e
54 changed files with 1884 additions and 1476 deletions
|
@ -38,13 +38,43 @@ impl<R> EventQueue<R> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove a file from the event queue, returning its callback if found
|
||||
pub fn remove(&mut self, fd: RawFd) -> Result<Option<Box<FnMut(usize) -> Result<Option<R>>>>> {
|
||||
if let Some(callback) = self.callbacks.remove(&fd) {
|
||||
syscall::fevent(fd, 0).map_err(|x| Error::from_sys(x))?;
|
||||
|
||||
Ok(Some(callback))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Send an event to a descriptor callback
|
||||
pub fn trigger(&mut self, fd: RawFd, count: usize) -> Result<Option<R>> {
|
||||
if let Some(callback) = self.callbacks.get_mut(&fd) {
|
||||
callback(count)
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
/// Send an event to all descriptor callbacks, useful for cleaning out buffers after init
|
||||
pub fn trigger_all(&mut self, count: usize) -> Result<Vec<R>> {
|
||||
let mut rets = Vec::new();
|
||||
for (_fd, callback) in self.callbacks.iter_mut() {
|
||||
if let Some(ret) = callback(count)? {
|
||||
rets.push(ret);
|
||||
}
|
||||
}
|
||||
Ok(rets)
|
||||
}
|
||||
|
||||
/// Process the event queue until a callback returns Some(R)
|
||||
pub fn run(&mut self) -> Result<R> {
|
||||
loop {
|
||||
let mut event = syscall::Event::default();
|
||||
self.file.read(&mut event)?;
|
||||
if let Some(callback) = self.callbacks.get_mut(&event.id) {
|
||||
if let Some(ret) = callback(event.data)? {
|
||||
if self.file.read(&mut event)? > 0 {
|
||||
if let Some(ret) = self.trigger(event.id, event.data)? {
|
||||
return Ok(ret);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use syscall::error::*;
|
|||
pub trait Resource {
|
||||
/// Duplicate the resource
|
||||
/// Returns `EPERM` if the operation is not supported.
|
||||
fn dup(&self) -> Result<Box<Self>> {
|
||||
fn dup(&self, _buf: &[u8]) -> Result<Box<Self>> {
|
||||
Err(Error::new(EPERM))
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ pub trait ResourceScheme<T: Resource> {
|
|||
SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
|
||||
SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid),
|
||||
|
||||
SYS_DUP => self.dup(packet.b),
|
||||
SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
|
||||
SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }),
|
||||
SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
|
||||
SYS_LSEEK => self.seek(packet.b, packet.c, packet.d),
|
||||
|
@ -54,9 +54,9 @@ pub trait ResourceScheme<T: Resource> {
|
|||
}
|
||||
|
||||
/* Resource operations */
|
||||
fn dup(&self, old_id: usize) -> Result<usize> {
|
||||
fn dup(&self, old_id: usize, buf: &[u8]) -> Result<usize> {
|
||||
let old = unsafe { &*(old_id as *const T) };
|
||||
let resource = old.dup()?;
|
||||
let resource = old.dup(buf)?;
|
||||
let resource_ptr = Box::into_raw(resource);
|
||||
Ok(resource_ptr as usize)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue