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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue