Commit 87a72617 authored by Jeremy Soller's avatar Jeremy Soller

Add O_NONBLOCK

parent 9c94a5cd
......@@ -3,6 +3,7 @@ use std::{cmp, mem, ptr, slice};
use dma::Dma;
use netutils::setcfg;
use syscall::error::{Error, EACCES, EWOULDBLOCK, Result};
use syscall::flag::O_NONBLOCK;
use syscall::scheme::Scheme;
const CTRL: u32 = 0x00;
......@@ -100,9 +101,9 @@ pub struct Intel8254x {
}
impl Scheme for Intel8254x {
fn open(&self, _path: &[u8], _flags: usize, uid: u32, _gid: u32) -> Result<usize> {
fn open(&self, _path: &[u8], flags: usize, uid: u32, _gid: u32) -> Result<usize> {
if uid == 0 {
Ok(0)
Ok(flags)
} else {
Err(Error::new(EACCES))
}
......@@ -112,7 +113,7 @@ impl Scheme for Intel8254x {
Ok(id)
}
fn read(&self, _id: usize, buf: &mut [u8]) -> Result<usize> {
fn read(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
let head = unsafe { self.read(RDH) };
let mut tail = unsafe { self.read(RDT) };
......@@ -140,8 +141,11 @@ impl Scheme for Intel8254x {
}
}
//Err(Error::new(EWOULDBLOCK))
Ok(0)
if id & O_NONBLOCK == O_NONBLOCK {
Ok(0)
} else {
Err(Error::new(EWOULDBLOCK))
}
}
fn write(&self, _id: usize, buf: &[u8]) -> Result<usize> {
......
......@@ -92,6 +92,11 @@ fn main() {
socket_packet.borrow_mut().write(&mut packet)?;
}
let next_read = device.next_read();
if next_read > 0 {
return Ok(Some(next_read));
}
Ok(None)
}).expect("e1000d: failed to catch events on IRQ file");
......
......@@ -4,6 +4,7 @@ use dma::Dma;
use io::{Mmio, Io, ReadOnly};
use netutils::setcfg;
use syscall::error::{Error, EACCES, EWOULDBLOCK, Result};
use syscall::flag::O_NONBLOCK;
use syscall::scheme::SchemeMut;
#[repr(packed)]
......@@ -75,9 +76,9 @@ pub struct Rtl8168 {
}
impl SchemeMut for Rtl8168 {
fn open(&mut self, _path: &[u8], _flags: usize, uid: u32, _gid: u32) -> Result<usize> {
fn open(&mut self, _path: &[u8], flags: usize, uid: u32, _gid: u32) -> Result<usize> {
if uid == 0 {
Ok(0)
Ok(flags)
} else {
Err(Error::new(EACCES))
}
......@@ -87,7 +88,7 @@ impl SchemeMut for Rtl8168 {
Ok(id)
}
fn read(&mut self, _id: usize, buf: &mut [u8]) -> Result<usize> {
fn read(&mut self, id: usize, buf: &mut [u8]) -> Result<usize> {
for (rd_i, rd) in self.receive_ring.iter_mut().enumerate() {
if ! rd.ctrl.readf(OWN) {
let rd_len = rd.ctrl.read() & 0x3FFF;
......@@ -107,7 +108,11 @@ impl SchemeMut for Rtl8168 {
}
}
Err(Error::new(EWOULDBLOCK))
if id & O_NONBLOCK == O_NONBLOCK {
Ok(0)
} else {
Err(Error::new(EWOULDBLOCK))
}
}
fn write(&mut self, _id: usize, buf: &[u8]) -> Result<usize> {
......@@ -197,6 +202,15 @@ impl Rtl8168 {
isr & imr
}
pub fn next_read(&self) -> usize {
for rd in self.receive_ring.iter() {
if ! rd.ctrl.readf(OWN) {
return rd.ctrl.read() as usize & 0x3FFF;
}
}
0
}
pub unsafe fn init(&mut self) {
let mac_low = self.regs.mac[0].read();
let mac_high = self.regs.mac[1].read();
......
......@@ -73,6 +73,11 @@ fn main() {
todo.remove(i);
}
}
let next_read = device_irq.borrow().next_read();
if next_read > 0 {
return Ok(Some(next_read));
}
}
Ok(None)
}).expect("rtl8168d: failed to catch events on IRQ file");
......@@ -92,6 +97,11 @@ fn main() {
socket_packet.borrow_mut().write(&mut packet)?;
}
let next_read = device.borrow().next_read();
if next_read > 0 {
return Ok(Some(next_read));
}
Ok(None)
}).expect("rtl8168d: failed to catch events on IRQ file");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment