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