Use new SchemeBlock trait (#29)

* Use new SchemeBlock trait

* Use EAGAIN over EWOULDBLOCK
This commit is contained in:
jD91mZM2
2018-05-30 18:55:05 +02:00
committed by Jeremy Soller
parent 6ffe327989
commit 7fe9c67a53
6 changed files with 89 additions and 91 deletions
Generated
+29 -29
View File
@@ -57,7 +57,7 @@ dependencies = [
"arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
"scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -77,7 +77,7 @@ version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -168,12 +168,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.0.0"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.40"
version = "0.2.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -218,17 +218,17 @@ dependencies = [
[[package]]
name = "netutils"
version = "0.1.0"
source = "git+https://github.com/redox-os/netutils.git#f1861a0caa73c5351a3594cc39a677af709b8cbe"
source = "git+https://github.com/redox-os/netutils.git#f1187fae0a1a02f532e72e1126dcb17bde64bd00"
dependencies = [
"arg_parser 0.1.0 (git+https://github.com/redox-os/arg-parser.git)",
"extra 0.1.0 (git+https://github.com/redox-os/libextra.git)",
"hyper 0.10.13 (registry+https://github.com/rust-lang/crates.io-index)",
"hyper-rustls 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)",
"ntpclient 0.0.1 (git+https://github.com/willem66745/ntpclient-rust)",
"pbr 1.0.1 (git+https://github.com/a8m/pb)",
"redox_event 0.1.0 (git+https://github.com/redox-os/event.git)",
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -251,7 +251,7 @@ name = "num_cpus"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -260,7 +260,7 @@ version = "1.0.1"
source = "git+https://github.com/a8m/pb#e1df7361a08e2c7e210a3e483e3086bfe62dfe71"
dependencies = [
"kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -273,7 +273,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "quick-error"
version = "1.2.1"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -282,7 +282,7 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -300,8 +300,8 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -311,7 +311,7 @@ name = "redox_event"
version = "0.1.0"
source = "git+https://github.com/redox-os/event.git#e9bf8ee4622cb82af2a10032ed711174b2188afd"
dependencies = [
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -323,18 +323,18 @@ dependencies = [
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"netutils 0.1.0 (git+https://github.com/redox-os/netutils.git)",
"redox_event 0.1.0 (git+https://github.com/redox-os/event.git)",
"redox_syscall 0.1.37 (git+https://github.com/redox-os/syscall.git)",
"redox_syscall 0.1.40 (git+https://github.com/redox-os/syscall.git)",
"smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp.git?rev=c418b60b5db93753999ae51d33ec4dc1d1631c69)",
]
[[package]]
name = "redox_syscall"
version = "0.1.37"
source = "git+https://github.com/redox-os/syscall.git#7dc00e7ea4162f8886412d936f14ea5b7d834d41"
version = "0.1.40"
source = "git+https://github.com/redox-os/syscall.git#0ab552da9a9587b360b5d9991ed9921300e5667b"
[[package]]
name = "redox_syscall"
version = "0.1.37"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -342,7 +342,7 @@ name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -352,7 +352,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -394,8 +394,8 @@ name = "termion"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -404,8 +404,8 @@ name = "time"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -531,8 +531,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a"
"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d"
"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b"
"checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739"
"checksum libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)" = "ac8ebf8343a981e2fa97042b14768f02ed3e1d602eac06cae6166df3c8ced206"
"checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b"
"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2"
"checksum managed 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "43e2737ecabe4ae36a68061398bf27d2bfd0763f4c3c837a398478459494c4b7"
@@ -545,13 +545,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
"checksum pbr 1.0.1 (git+https://github.com/a8m/pb)" = "<none>"
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
"checksum quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eda5fe9b71976e62bc81b781206aaa076401769b2143379d3eb2118388babac4"
"checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
"checksum rayon 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c51c07654ddd93f6cb543c7a849863b03abc7e82591afda6dc8ad4ac3ac4a"
"checksum rayon-core 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d24ad214285a7729b174ed6d3bcfcb80177807f959d95fafd5bfc5c4f201ac8"
"checksum redox_event 0.1.0 (git+https://github.com/redox-os/event.git)" = "<none>"
"checksum redox_syscall 0.1.37 (git+https://github.com/redox-os/syscall.git)" = "<none>"
"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
"checksum redox_syscall 0.1.40 (git+https://github.com/redox-os/syscall.git)" = "<none>"
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum ring 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2a6dc7fc06a05e6de183c5b97058582e9da2de0c136eafe49609769c507724"
"checksum rustls 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17727f4b991294da2c84d75a43c003151ff58072212768800f66c56ee46dca43"
+8 -8
View File
@@ -163,7 +163,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> {
&mut self,
file: &mut SocketFile<Self::DataT>,
buf: &[u8],
) -> SyscallResult<usize> {
) -> SyscallResult<Option<usize>> {
if self.can_send() {
match file.data.socket_type {
IcmpSocketType::Echo => {
@@ -183,16 +183,16 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> {
let mut icmp_packet = Icmpv4Packet::new(icmp_payload);
//TODO: replace Default with actual caps
icmp_repr.emit(&mut icmp_packet, &Default::default());
Ok(buf.len())
Ok(Some(buf.len()))
}
IcmpSocketType::Udp => {
Err(SyscallError::new(syscall::EINVAL))
}
}
} else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK {
Ok(0)
Err(SyscallError::new(syscall::EAGAIN))
} else {
Err(SyscallError::new(syscall::EWOULDBLOCK))
Ok(None) // internally scheduled to re-read
}
}
@@ -200,7 +200,7 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> {
&mut self,
file: &mut SocketFile<Self::DataT>,
buf: &mut [u8],
) -> SyscallResult<usize> {
) -> SyscallResult<Option<usize>> {
while self.can_recv() {
let (payload, _) = self.recv().expect("Can't recv icmp packet");
let icmp_packet = Icmpv4Packet::new(&payload);
@@ -217,14 +217,14 @@ impl<'a, 'b> SchemeSocket for IcmpSocket<'a, 'b> {
buf[mem::size_of::<u16>() + i] = data[i];
}
return Ok(mem::size_of::<u16>() + data.len());
return Ok(Some(mem::size_of::<u16>() + data.len()));
}
}
if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK {
Ok(0)
Err(SyscallError::new(syscall::EAGAIN))
} else {
Err(SyscallError::new(syscall::EWOULDBLOCK))
Ok(None) // internally scheduled to re-read
}
}
+8 -8
View File
@@ -88,14 +88,14 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> {
&mut self,
file: &mut SocketFile<Self::DataT>,
buf: &[u8],
) -> SyscallResult<usize> {
) -> SyscallResult<Option<usize>> {
if self.can_send() {
self.send_slice(buf).expect("Can't send slice");
Ok(buf.len())
Ok(Some(buf.len()))
} else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK {
Ok(0)
Err(SyscallError::new(syscall::EAGAIN))
} else {
Err(SyscallError::new(syscall::EWOULDBLOCK))
Ok(None) // internally scheduled to re-read
}
}
@@ -103,14 +103,14 @@ impl<'a, 'b> SchemeSocket for RawSocket<'a, 'b> {
&mut self,
file: &mut SocketFile<Self::DataT>,
buf: &mut [u8],
) -> SyscallResult<usize> {
) -> SyscallResult<Option<usize>> {
if self.can_recv() {
let length = self.recv_slice(buf).expect("Can't receive slice");
Ok(length)
Ok(Some(length))
} else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK {
Ok(0)
Err(SyscallError::new(syscall::EAGAIN))
} else {
Err(SyscallError::new(syscall::EWOULDBLOCK))
Ok(None) // internally scheduled to re-read
}
}
+31 -33
View File
@@ -10,7 +10,7 @@ use std::ops::DerefMut;
use std::rc::Rc;
use std::str;
use syscall::data::TimeSpec;
use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeMut};
use syscall::{Error as SyscallError, Packet as SyscallPacket, Result as SyscallResult, SchemeBlockMut};
use syscall;
use redox_netstack::error::{Error, Result};
@@ -139,9 +139,9 @@ where
fn close_file(&self, &SchemeFile<Self>, &mut Self::SchemeDataT) -> SyscallResult<()>;
fn write_buf(&mut self, &mut SocketFile<Self::DataT>, buf: &[u8]) -> SyscallResult<usize>;
fn write_buf(&mut self, &mut SocketFile<Self::DataT>, buf: &[u8]) -> SyscallResult<Option<usize>>;
fn read_buf(&mut self, &mut SocketFile<Self::DataT>, buf: &mut [u8]) -> SyscallResult<usize>;
fn read_buf(&mut self, &mut SocketFile<Self::DataT>, buf: &mut [u8]) -> SyscallResult<Option<usize>>;
fn fpath(&self, &SchemeFile<Self>, &mut [u8]) -> SyscallResult<usize>;
@@ -190,12 +190,10 @@ where
if self.scheme_file.read(&mut packet)? == 0 {
break;
}
let a = packet.a;
self.handle(&mut packet);
if packet.a != (-syscall::EWOULDBLOCK) as usize {
if let Some(a) = self.handle(&mut packet) {
packet.a = a;
self.scheme_file.write_all(&packet)?;
} else {
packet.a = a;
self.handle_block(packet)?;
}
}
@@ -271,8 +269,10 @@ where
for wait_handle in input_queue.drain(..) {
let mut packet = wait_handle.packet;
self.handle(&mut packet);
if packet.a == (-syscall::EWOULDBLOCK) as usize {
if let Some(a) = self.handle(&mut packet) {
packet.a = a;
self.scheme_file.write_all(&packet)?;
} else {
match wait_handle.until {
Some(until)
if (until.tv_sec < cur_time.tv_sec
@@ -286,8 +286,6 @@ where
to_retain.push(wait_handle);
}
}
} else {
self.scheme_file.write_all(&packet)?;
}
}
@@ -474,11 +472,11 @@ where
}
}
impl<SocketT> syscall::SchemeMut for SocketScheme<SocketT>
impl<SocketT> syscall::SchemeBlockMut for SocketScheme<SocketT>
where
SocketT: SchemeSocket + AnySocket<'static, 'static>,
{
fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> SyscallResult<usize> {
fn open(&mut self, url: &[u8], flags: usize, uid: u32, _gid: u32) -> SyscallResult<Option<usize>> {
let path = str::from_utf8(url).or_else(|_| Err(SyscallError::new(syscall::EINVAL)))?;
if path.is_empty() {
@@ -493,7 +491,7 @@ where
self.nulls.insert(id, null);
Ok(id)
Ok(Some(id))
} else {
let (socket_handle, data) = SocketT::new_socket(
&mut self.socket_set.borrow_mut(),
@@ -518,13 +516,13 @@ where
self.files.insert(id, file);
Ok(id)
Ok(Some(id))
}
}
fn close(&mut self, fd: usize) -> SyscallResult<usize> {
fn close(&mut self, fd: usize) -> SyscallResult<Option<usize>> {
if let Some(_null) = self.nulls.remove(&fd) {
return Ok(0);
return Ok(Some(0));
}
let socket_handle = {
@@ -557,10 +555,10 @@ where
socket_set.release(socket_handle);
//TODO: removing sockets in release should make prune unnecessary
socket_set.prune();
Ok(0)
Ok(Some(0))
}
fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult<usize> {
fn write(&mut self, fd: usize, buf: &[u8]) -> SyscallResult<Option<usize>> {
let (fd, setting) = {
let file = self.files
.get_mut(&fd)
@@ -577,10 +575,10 @@ where
}
}
};
self.update_setting(fd, setting, buf)
self.update_setting(fd, setting, buf).map(Some)
}
fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult<usize> {
fn read(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult<Option<usize>> {
let (fd, setting) = {
let file = self.files
.get_mut(&fd)
@@ -596,10 +594,10 @@ where
}
}
};
self.get_setting(fd, setting, buf)
self.get_setting(fd, setting, buf).map(Some)
}
fn dup(&mut self, fd: usize, buf: &[u8]) -> SyscallResult<usize> {
fn dup(&mut self, fd: usize, buf: &[u8]) -> SyscallResult<Option<usize>> {
if let Some((flags, uid, gid)) = self.nulls
.get(&fd)
.map(|null| (null.flags, null.uid, null.gid))
@@ -672,10 +670,10 @@ where
self.files.insert(id, new_file);
self.next_fd += 1;
Ok(id)
Ok(Some(id))
}
fn fevent(&mut self, fd: usize, events: usize) -> SyscallResult<usize> {
fn fevent(&mut self, fd: usize, events: usize) -> SyscallResult<Option<usize>> {
let file = self.files
.get_mut(&fd)
.ok_or_else(|| SyscallError::new(syscall::EBADF))?;
@@ -685,23 +683,23 @@ where
file.events = events;
file.read_notified = false; // resend missed events
file.write_notified = false;
Ok(fd)
Ok(Some(fd))
}
}
}
fn fsync(&mut self, fd: usize) -> SyscallResult<usize> {
fn fsync(&mut self, fd: usize) -> SyscallResult<Option<usize>> {
{
let _file = self.files
.get_mut(&fd)
.ok_or_else(|| SyscallError::new(syscall::EBADF))?;
}
Ok(0)
Ok(Some(0))
// TODO Implement fsyncing
// self.0.network_fsync()
}
fn fpath(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult<usize> {
fn fpath(&mut self, fd: usize, buf: &mut [u8]) -> SyscallResult<Option<usize>> {
let file = self.files
.get_mut(&fd)
.ok_or_else(|| SyscallError::new(syscall::EBADF))?;
@@ -709,20 +707,20 @@ where
let mut socket_set = self.socket_set.borrow_mut();
let socket = socket_set.get::<SocketT>(file.socket_handle());
socket.fpath(file, buf)
socket.fpath(file, buf).map(Some)
}
fn fcntl(&mut self, fd: usize, cmd: usize, arg: usize) -> SyscallResult<usize> {
fn fcntl(&mut self, fd: usize, cmd: usize, arg: usize) -> SyscallResult<Option<usize>> {
let file = self.files
.get_mut(&fd)
.ok_or_else(|| SyscallError::new(syscall::EBADF))?;
if let SchemeFile::Socket(ref mut socket_file) = *file {
match cmd {
syscall::F_GETFL => Ok(socket_file.flags),
syscall::F_GETFL => Ok(Some(socket_file.flags)),
syscall::F_SETFL => {
socket_file.flags = arg & !syscall::O_ACCMODE;
Ok(0)
Ok(Some(0))
}
_ => Err(SyscallError::new(syscall::EINVAL)),
}
+7 -7
View File
@@ -113,16 +113,16 @@ impl<'a> SchemeSocket for TcpSocket<'a> {
&mut self,
file: &mut SocketFile<Self::DataT>,
buf: &[u8],
) -> SyscallResult<usize> {
) -> SyscallResult<Option<usize>> {
if !self.is_active() {
Err(SyscallError::new(syscall::ENOTCONN))
} else if self.can_send() {
self.send_slice(buf).expect("Can't send slice");
Ok(buf.len())
Ok(Some(buf.len()))
} else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK {
Err(SyscallError::new(syscall::EAGAIN))
} else {
Err(SyscallError::new(syscall::EWOULDBLOCK))
Ok(None) // internally scheduled to re-read
}
}
@@ -130,16 +130,16 @@ impl<'a> SchemeSocket for TcpSocket<'a> {
&mut self,
file: &mut SocketFile<Self::DataT>,
buf: &mut [u8],
) -> SyscallResult<usize> {
) -> SyscallResult<Option<usize>> {
if !self.is_active() {
Err(SyscallError::new(syscall::ENOTCONN))
} else if self.can_recv() {
let length = self.recv_slice(buf).expect("Can't receive slice");
Ok(length)
Ok(Some(length))
} else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK {
Err(SyscallError::new(syscall::EAGAIN))
} else {
Err(SyscallError::new(syscall::EWOULDBLOCK))
Ok(None) // internally scheduled to re-read
}
}
@@ -162,7 +162,7 @@ impl<'a> SchemeSocket for TcpSocket<'a> {
if tcp_handle.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK {
return Err(SyscallError::new(syscall::EAGAIN));
} else {
return Err(SyscallError::new(syscall::EWOULDBLOCK));
return Err(SyscallError::new(syscall::EAGAIN));
}
}
trace!("TCP creating new listening socket");
+6 -6
View File
@@ -109,17 +109,17 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> {
&mut self,
file: &mut SocketFile<Self::DataT>,
buf: &[u8],
) -> SyscallResult<usize> {
) -> SyscallResult<Option<usize>> {
if !file.data.is_specified() {
return Err(SyscallError::new(syscall::EADDRNOTAVAIL));
}
if self.can_send() {
self.send_slice(buf, file.data).expect("Can't send slice");
Ok(buf.len())
Ok(Some(buf.len()))
} else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK {
Err(SyscallError::new(syscall::EAGAIN))
} else {
Err(SyscallError::new(syscall::EWOULDBLOCK))
Ok(None) // internally scheduled to re-read
}
}
@@ -127,14 +127,14 @@ impl<'a, 'b> SchemeSocket for UdpSocket<'a, 'b> {
&mut self,
file: &mut SocketFile<Self::DataT>,
buf: &mut [u8],
) -> SyscallResult<usize> {
) -> SyscallResult<Option<usize>> {
if self.can_recv() {
let (length, _) = self.recv_slice(buf).expect("Can't receive slice");
Ok(length)
Ok(Some(length))
} else if file.flags & syscall::O_NONBLOCK == syscall::O_NONBLOCK {
Err(SyscallError::new(syscall::EAGAIN))
} else {
Err(SyscallError::new(syscall::EWOULDBLOCK))
Ok(None) // internally scheduled to re-read
}
}