summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/epoll.rs68
-rw-r--r--src/sys/select.rs1
-rw-r--r--src/sys/signal.rs36
-rw-r--r--src/sys/socket/addr.rs4
-rw-r--r--src/sys/socket/consts.rs1
5 files changed, 68 insertions, 42 deletions
diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs
index 2090a0df..9774318f 100644
--- a/src/sys/epoll.rs
+++ b/src/sys/epoll.rs
@@ -1,21 +1,10 @@
use {Errno, Result};
-use libc::c_int;
+use libc::{self, c_int};
use std::os::unix::io::RawFd;
-mod ffi {
- use libc::{c_int};
- use super::EpollEvent;
-
- extern {
- pub fn epoll_create(size: c_int) -> c_int;
- pub fn epoll_ctl(epfd: c_int, op: c_int, fd: c_int, event: *const EpollEvent) -> c_int;
- pub fn epoll_wait(epfd: c_int, events: *mut EpollEvent, max_events: c_int, timeout: c_int) -> c_int;
- }
-}
-
bitflags!(
#[repr(C)]
- flags EpollEventKind: u32 {
+ flags EpollFlags: u32 {
const EPOLLIN = 0x001,
const EPOLLPRI = 0x002,
const EPOLLOUT = 0x004,
@@ -42,46 +31,49 @@ pub enum EpollOp {
EpollCtlMod = 3
}
-#[cfg(not(target_arch = "x86_64"))]
-#[derive(Clone, Copy)]
-#[repr(C)]
-pub struct EpollEvent {
- pub events: EpollEventKind,
- pub data: u64
+libc_bitflags!{
+ flags EpollCreateFlags: c_int {
+ EPOLL_CLOEXEC,
+ }
}
-#[cfg(target_arch = "x86_64")]
#[derive(Clone, Copy)]
-#[repr(C, packed)]
+#[repr(C)]
pub struct EpollEvent {
- pub events: EpollEventKind,
- pub data: u64
+ event: libc::epoll_event,
}
-#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
-#[test]
-fn test_epoll_event_size() {
- use std::mem::size_of;
- assert_eq!(size_of::<EpollEvent>(), 12);
-}
+impl EpollEvent {
+ pub fn new(events: EpollFlags, data: u64) -> EpollEvent {
+ EpollEvent { event: libc::epoll_event { events: events.bits(), u64: data } }
+ }
+
+ pub fn events(&self) -> EpollFlags {
+ EpollFlags::from_bits(self.event.events).unwrap()
+ }
-#[cfg(target_arch = "arm")]
-#[test]
-fn test_epoll_event_size() {
- use std::mem::size_of;
- assert_eq!(size_of::<EpollEvent>(), 16);
+ pub fn data(&self) -> u64 {
+ self.event.u64
+ }
}
#[inline]
pub fn epoll_create() -> Result<RawFd> {
- let res = unsafe { ffi::epoll_create(1024) };
+ let res = unsafe { libc::epoll_create(1024) };
+
+ Errno::result(res)
+}
+
+#[inline]
+pub fn epoll_create1(flags: EpollCreateFlags) -> Result<RawFd> {
+ let res = unsafe { libc::epoll_create1(flags.bits()) };
Errno::result(res)
}
#[inline]
-pub fn epoll_ctl(epfd: RawFd, op: EpollOp, fd: RawFd, event: &EpollEvent) -> Result<()> {
- let res = unsafe { ffi::epoll_ctl(epfd, op as c_int, fd, event as *const EpollEvent) };
+pub fn epoll_ctl(epfd: RawFd, op: EpollOp, fd: RawFd, event: &mut EpollEvent) -> Result<()> {
+ let res = unsafe { libc::epoll_ctl(epfd, op as c_int, fd, &mut event.event) };
Errno::result(res).map(drop)
}
@@ -89,7 +81,7 @@ pub fn epoll_ctl(epfd: RawFd, op: EpollOp, fd: RawFd, event: &EpollEvent) -> Res
#[inline]
pub fn epoll_wait(epfd: RawFd, events: &mut [EpollEvent], timeout_ms: isize) -> Result<usize> {
let res = unsafe {
- ffi::epoll_wait(epfd, events.as_mut_ptr(), events.len() as c_int, timeout_ms as c_int)
+ libc::epoll_wait(epfd, events.as_mut_ptr() as *mut libc::epoll_event, events.len() as c_int, timeout_ms as c_int)
};
Errno::result(res).map(|r| r as usize)
diff --git a/src/sys/select.rs b/src/sys/select.rs
index 1b47d759..28b664aa 100644
--- a/src/sys/select.rs
+++ b/src/sys/select.rs
@@ -8,6 +8,7 @@ pub const FD_SETSIZE: RawFd = 1024;
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[repr(C)]
+#[derive(Clone)]
pub struct FdSet {
bits: [i32; FD_SETSIZE as usize / 32]
}
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index 18827332..bdc25b47 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -28,7 +28,7 @@ pub enum Signal {
SIGPIPE = libc::SIGPIPE,
SIGALRM = libc::SIGALRM,
SIGTERM = libc::SIGTERM,
- #[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
+ #[cfg(all(any(target_os = "linux", target_os = "android", target_os = "emscripten"), not(target_arch = "mips")))]
SIGSTKFLT = libc::SIGSTKFLT,
SIGCHLD = libc::SIGCHLD,
SIGCONT = libc::SIGCONT,
@@ -54,7 +54,7 @@ pub enum Signal {
pub use self::Signal::*;
-#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
+#[cfg(all(any(target_os = "linux", target_os = "android", target_os = "emscripten"), not(target_arch = "mips")))]
const SIGNALS: [Signal; 31] = [
SIGHUP,
SIGINT,
@@ -87,6 +87,38 @@ const SIGNALS: [Signal; 31] = [
SIGIO,
SIGPWR,
SIGSYS];
+#[cfg(all(any(target_os = "linux", target_os = "android", target_os = "emscripten"), target_arch = "mips"))]
+const SIGNALS: [Signal; 30] = [
+ SIGHUP,
+ SIGINT,
+ SIGQUIT,
+ SIGILL,
+ SIGTRAP,
+ SIGABRT,
+ SIGBUS,
+ SIGFPE,
+ SIGKILL,
+ SIGUSR1,
+ SIGSEGV,
+ SIGUSR2,
+ SIGPIPE,
+ SIGALRM,
+ SIGTERM,
+ SIGCHLD,
+ SIGCONT,
+ SIGSTOP,
+ SIGTSTP,
+ SIGTTIN,
+ SIGTTOU,
+ SIGURG,
+ SIGXCPU,
+ SIGXFSZ,
+ SIGVTALRM,
+ SIGPROF,
+ SIGWINCH,
+ SIGIO,
+ SIGPWR,
+ SIGSYS];
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "emscripten")))]
const SIGNALS: [Signal; 31] = [
SIGHUP,
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index 22970d8b..e3c1401c 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -391,7 +391,7 @@ impl UnixAddr {
.. mem::zeroed()
};
- if path.len() > ret.sun_path.len() {
+ if path.len() + 1 > ret.sun_path.len() {
return Err(Error::Sys(Errno::ENAMETOOLONG));
}
@@ -401,7 +401,7 @@ impl UnixAddr {
ret.sun_path.as_mut_ptr().offset(1) as *mut u8,
path.len());
- Ok(UnixAddr(ret, path.len()))
+ Ok(UnixAddr(ret, path.len() + 1))
}
}
diff --git a/src/sys/socket/consts.rs b/src/sys/socket/consts.rs
index aeeea5c3..63eaf28a 100644
--- a/src/sys/socket/consts.rs
+++ b/src/sys/socket/consts.rs
@@ -98,6 +98,7 @@ mod os {
const MSG_DONTWAIT = 0x0040,
const MSG_EOR = 0x0080,
const MSG_ERRQUEUE = 0x2000,
+ const MSG_CMSG_CLOEXEC = 0x40000000,
}
}