Commit e6e31dd3 authored by Jeremy Soller's avatar Jeremy Soller

Format

parent f8fe67e7
Pipeline #4010 failed with stages
in 8 minutes and 12 seconds
......@@ -3,13 +3,9 @@
use core::{mem, slice};
use fs::File;
use header::sys_epoll::{
epoll_create1, EPOLL_CLOEXEC,
epoll_ctl, EPOLL_CTL_ADD,
epoll_wait,
EPOLLIN, EPOLLPRI, EPOLLOUT, EPOLLERR, EPOLLHUP, EPOLLNVAL,
epoll_data, epoll_event
};
use header::sys_epoll::{epoll_create1, epoll_ctl, epoll_data, epoll_event, epoll_wait, EPOLLERR,
EPOLLHUP, EPOLLIN, EPOLLNVAL, EPOLLOUT, EPOLLPRI, EPOLL_CLOEXEC,
EPOLL_CTL_ADD};
use platform::types::*;
pub const POLLIN: c_short = 0x001;
......@@ -35,7 +31,7 @@ pub fn poll_epoll(fds: &mut [pollfd], timeout: c_int) -> c_int {
(POLLOUT, EPOLLOUT),
(POLLERR, EPOLLERR),
(POLLHUP, EPOLLHUP),
(POLLNVAL, EPOLLNVAL)
(POLLNVAL, EPOLLNVAL),
];
let ep = {
......@@ -51,9 +47,7 @@ pub fn poll_epoll(fds: &mut [pollfd], timeout: c_int) -> c_int {
let mut event = epoll_event {
events: 0,
data: epoll_data {
u64: i as u64,
},
data: epoll_data { u64: i as u64 },
..Default::default()
};
......@@ -71,12 +65,7 @@ pub fn poll_epoll(fds: &mut [pollfd], timeout: c_int) -> c_int {
}
let mut events: [epoll_event; 32] = unsafe { mem::zeroed() };
let res = epoll_wait(
*ep,
events.as_mut_ptr(),
events.len() as c_int,
timeout
);
let res = epoll_wait(*ep, events.as_mut_ptr(), events.len() as c_int, timeout);
if res < 0 {
return -1;
}
......@@ -106,10 +95,7 @@ pub fn poll_epoll(fds: &mut [pollfd], timeout: c_int) -> c_int {
#[no_mangle]
pub unsafe extern "C" fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: c_int) -> c_int {
trace_expr!(
poll_epoll(
slice::from_raw_parts_mut(fds, nfds as usize),
timeout
),
poll_epoll(slice::from_raw_parts_mut(fds, nfds as usize), timeout),
"poll({:p}, {}, {})",
fds,
nfds,
......
......@@ -3,8 +3,8 @@
use core::ptr;
use header::signal::sigset_t;
use platform::{PalEpoll, Sys};
use platform::types::*;
use platform::{PalEpoll, Sys};
pub use self::sys::*;
......@@ -55,11 +55,7 @@ pub extern "C" fn epoll_create(_size: c_int) -> c_int {
#[no_mangle]
pub extern "C" fn epoll_create1(flags: c_int) -> c_int {
trace_expr!(
Sys::epoll_create1(flags),
"epoll_create1({:#x})",
flags
)
trace_expr!(Sys::epoll_create1(flags), "epoll_create1({:#x})", flags)
}
#[no_mangle]
......@@ -75,12 +71,23 @@ pub extern "C" fn epoll_ctl(epfd: c_int, op: c_int, fd: c_int, event: *mut epoll
}
#[no_mangle]
pub extern "C" fn epoll_wait(epfd: c_int, events: *mut epoll_event, maxevents: c_int, timeout: c_int) -> c_int {
pub extern "C" fn epoll_wait(
epfd: c_int,
events: *mut epoll_event,
maxevents: c_int,
timeout: c_int,
) -> c_int {
epoll_pwait(epfd, events, maxevents, timeout, ptr::null())
}
#[no_mangle]
pub extern "C" fn epoll_pwait(epfd: c_int, events: *mut epoll_event, maxevents: c_int, timeout: c_int, sigmask: *const sigset_t) -> c_int {
pub extern "C" fn epoll_pwait(
epfd: c_int,
events: *mut epoll_event,
maxevents: c_int,
timeout: c_int,
sigmask: *const sigset_t,
) -> c_int {
trace_expr!(
Sys::epoll_pwait(epfd, events, maxevents, timeout, sigmask),
"epoll_pwait({}, {:p}, {}, {}, {:p})",
......
......@@ -4,13 +4,8 @@ use core::mem;
use fs::File;
use header::errno;
use header::sys_epoll::{
epoll_create1, EPOLL_CLOEXEC,
epoll_ctl, EPOLL_CTL_ADD,
epoll_wait,
EPOLLIN, EPOLLOUT, EPOLLERR,
epoll_data, epoll_event
};
use header::sys_epoll::{epoll_create1, epoll_ctl, epoll_data, epoll_event, epoll_wait, EPOLLERR,
EPOLLIN, EPOLLOUT, EPOLL_CLOEXEC, EPOLL_CTL_ADD};
use header::sys_time::timeval;
use platform;
use platform::types::*;
......@@ -57,7 +52,7 @@ pub fn select_epoll(
mut readfds: Option<&mut fd_set>,
mut writefds: Option<&mut fd_set>,
mut exceptfds: Option<&mut fd_set>,
timeout: Option<&mut timeval>
timeout: Option<&mut timeval>,
) -> c_int {
if nfds < 0 || nfds > FD_SETSIZE as i32 {
unsafe { platform::errno = errno::EINVAL };
......@@ -79,9 +74,7 @@ pub fn select_epoll(
if fd_set.isset(fd) {
let mut event = epoll_event {
events: EPOLLIN,
data: epoll_data {
fd: fd,
},
data: epoll_data { fd: fd },
..Default::default()
};
if epoll_ctl(*ep, EPOLL_CTL_ADD, fd, &mut event) < 0 {
......@@ -99,9 +92,7 @@ pub fn select_epoll(
if fd_set.isset(fd) {
let mut event = epoll_event {
events: EPOLLOUT,
data: epoll_data {
fd: fd,
},
data: epoll_data { fd: fd },
..Default::default()
};
if epoll_ctl(*ep, EPOLL_CTL_ADD, fd, &mut event) < 0 {
......@@ -119,9 +110,7 @@ pub fn select_epoll(
if fd_set.isset(fd) {
let mut event = epoll_event {
events: EPOLLERR,
data: epoll_data {
fd: fd,
},
data: epoll_data { fd: fd },
..Default::default()
};
if epoll_ctl(*ep, EPOLL_CTL_ADD, fd, &mut event) < 0 {
......@@ -145,17 +134,16 @@ pub fn select_epoll(
match timeout {
Some(timeout) => {
//TODO: Check for overflow
((timeout.tv_sec as c_int) * 1000) +
((timeout.tv_usec as c_int) / 1000)
},
None => -1
((timeout.tv_sec as c_int) * 1000) + ((timeout.tv_usec as c_int) / 1000)
}
None => -1,
}
};
let res = epoll_wait(
*ep,
events.as_mut_ptr(),
events.len() as c_int,
epoll_timeout
epoll_timeout,
);
if res < 0 {
return -1;
......
......@@ -360,8 +360,10 @@ pub unsafe extern "C" fn timegm(tm: *mut tm) -> time_t {
let h = (*tm).tm_hour as time_t;
let mi = (*tm).tm_min as time_t;
let s = (*tm).tm_sec as time_t;
(365*y + y/4 - y/100 + y/400 + 3*(m+1)/5 + 30*m + d - 719561)
* 86400 + 3600 * h + 60 * mi + s
(365 * y + y / 4 - y / 100 + y / 400 + 3 * (m + 1) / 5 + 30 * m + d - 719561) * 86400
+ 3600 * h
+ 60 * mi
+ s
}
// #[no_mangle]
......
......@@ -13,7 +13,22 @@ impl PalEpoll for Sys {
unsafe { e(syscall!(EPOLL_CTL, epfd, op, fd, event)) as c_int }
}
fn epoll_pwait(epfd: c_int, events: *mut epoll_event, maxevents: c_int, timeout: c_int, sigmask: *const sigset_t) -> c_int {
unsafe { e(syscall!(EPOLL_PWAIT, epfd, events, maxevents, timeout, sigmask)) as c_int }
fn epoll_pwait(
epfd: c_int,
events: *mut epoll_event,
maxevents: c_int,
timeout: c_int,
sigmask: *const sigset_t,
) -> c_int {
unsafe {
e(syscall!(
EPOLL_PWAIT,
epfd,
events,
maxevents,
timeout,
sigmask
)) as c_int
}
}
}
......@@ -6,5 +6,11 @@ use header::sys_epoll::epoll_event;
pub trait PalEpoll: Pal {
fn epoll_create1(flags: c_int) -> c_int;
fn epoll_ctl(epfd: c_int, op: c_int, fd: c_int, event: *mut epoll_event) -> c_int;
fn epoll_pwait(epfd: c_int, events: *mut epoll_event, maxevents: c_int, timeout: c_int, sigmask: *const sigset_t) -> c_int;
fn epoll_pwait(
epfd: c_int,
events: *mut epoll_event,
maxevents: c_int,
timeout: c_int,
sigmask: *const sigset_t,
) -> c_int;
}
......@@ -5,11 +5,11 @@ use super::Sys;
use c_str::CStr;
use core::{mem, slice};
use fs::File;
use io::prelude::*;
use header::errno::*;
use header::fcntl::*;
use header::signal::sigset_t;
use header::sys_epoll::*;
use io::prelude::*;
use syscall::data::{Event, TimeSpec};
use syscall::flag::EVENT_READ;
......@@ -18,22 +18,31 @@ impl PalEpoll for Sys {
Sys::open(
CStr::from_bytes_with_nul(b"event:\0").unwrap(),
O_RDWR | flags,
0
0,
)
}
fn epoll_ctl(epfd: c_int, op: c_int, fd: c_int, event: *mut epoll_event) -> c_int {
Sys::write(epfd, &Event {
id: fd as usize,
flags: unsafe { (*event).events as usize },
Sys::write(
epfd,
&Event {
id: fd as usize,
flags: unsafe { (*event).events as usize },
// NOTE: Danger when using non 64-bit systems. If this is
// needed, use a box or something
data: unsafe { mem::transmute((*event).data) }
}) as c_int
// NOTE: Danger when using non 64-bit systems. If this is
// needed, use a box or something
data: unsafe { mem::transmute((*event).data) },
},
) as c_int
}
fn epoll_pwait(epfd: c_int, mut events: *mut epoll_event, maxevents: c_int, timeout: c_int, _sigset: *const sigset_t) -> c_int {
fn epoll_pwait(
epfd: c_int,
mut events: *mut epoll_event,
maxevents: c_int,
timeout: c_int,
_sigset: *const sigset_t,
) -> c_int {
// TODO: sigset
let _timer;
......@@ -51,21 +60,24 @@ impl PalEpoll for Sys {
return -1;
}
if Sys::write(epfd, &Event {
id: timer.fd as usize,
flags: EVENT_READ,
data: 0
}) == -1 {
if Sys::write(
epfd,
&Event {
id: timer.fd as usize,
flags: EVENT_READ,
data: 0,
},
) == -1
{
return -1;
}
}
}
}
let bytes_read = Sys::read(epfd, unsafe { slice::from_raw_parts_mut(
events as *mut u8,
maxevents as usize
) });
let bytes_read = Sys::read(epfd, unsafe {
slice::from_raw_parts_mut(events as *mut u8, maxevents as usize)
});
if bytes_read == -1 {
return -1;
}
......
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