Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions core/src/net/operator/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use windows_sys::Win32::Networking::WinSock::{
getsockopt, setsockopt, AcceptEx, WSAGetLastError, WSARecv, WSASend, WSASocketW,
INVALID_SOCKET, LPCONDITIONPROC, LPWSAOVERLAPPED_COMPLETION_ROUTINE, SEND_RECV_FLAGS, SOCKADDR,
SOCKADDR_IN, SOCKET, SOCKET_ERROR, SOL_SOCKET, SO_PROTOCOL_INFO, SO_UPDATE_ACCEPT_CONTEXT,
WSABUF, WSAPROTOCOL_INFOW, WSA_FLAG_OVERLAPPED, WSA_IO_PENDING,
WSABUF, WSAEINPROGRESS, WSAENETDOWN, WSAPROTOCOL_INFOW, WSA_FLAG_OVERLAPPED, WSA_IO_PENDING,
};
use windows_sys::Win32::Storage::FileSystem::SetFileCompletionNotificationModes;
use windows_sys::Win32::System::WindowsProgramming::FILE_SKIP_SET_EVENT_ON_HANDLE;
Expand Down Expand Up @@ -159,7 +159,6 @@ impl<'o> Operator<'o> {
for entry in entries {
let mut cqe = *Box::from_raw(entry.lpOverlapped.cast::<Overlapped>());
// resolve completed read/write tasks
// todo refactor IOCP impl
cqe.result = match cqe.syscall_name {
SyscallName::accept => {
if setsockopt(
Expand All @@ -172,7 +171,7 @@ impl<'o> Operator<'o> {
{
cqe.socket.try_into().expect("result overflow")
} else {
-c_longlong::from(windows_sys::Win32::Foundation::GetLastError())
-c_longlong::from(WSAENETDOWN)
}
}
SyscallName::recv
Expand All @@ -183,7 +182,7 @@ impl<'o> Operator<'o> {
if r > 0 {
r
} else {
-c_longlong::from(windows_sys::Win32::Foundation::GetLastError())
-c_longlong::from(WSAEINPROGRESS)
}
}
_ => panic!("unsupported"),
Expand Down Expand Up @@ -273,6 +272,7 @@ impl<'o> Operator<'o> {
overlapped.token = user_data;
overlapped.syscall_name = syscall_name;
overlapped.socket = socket;
overlapped.result = -c_longlong::from(WSAENETDOWN);
let mut buf: Vec<u8> = Vec::with_capacity(size as usize * 2);
while AcceptEx(
fd,
Expand Down Expand Up @@ -364,6 +364,7 @@ impl<'o> Operator<'o> {
overlapped.from_fd = fd;
overlapped.token = user_data;
overlapped.syscall_name = syscall_name;
overlapped.result = -c_longlong::from(WSAEINPROGRESS);
if WSARecv(
fd,
buf,
Expand Down Expand Up @@ -457,6 +458,7 @@ impl<'o> Operator<'o> {
overlapped.from_fd = fd;
overlapped.token = user_data;
overlapped.syscall_name = syscall_name;
overlapped.result = -c_longlong::from(WSAEINPROGRESS);
if WSASend(
fd,
buf,
Expand Down
25 changes: 4 additions & 21 deletions core/src/syscall/unix/accept.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
use libc::{sockaddr, socklen_t};
use once_cell::sync::Lazy;
use std::ffi::c_int;

#[must_use]
pub extern "C" fn accept(
fn_ptr: Option<&extern "C" fn(c_int, *mut sockaddr, *mut socklen_t) -> c_int>,
fd: c_int,
address: *mut sockaddr,
address_len: *mut socklen_t,
) -> c_int {
cfg_if::cfg_if! {
if #[cfg(all(target_os = "linux", feature = "io_uring"))] {
static CHAIN: Lazy<
AcceptSyscallFacade<IoUringAcceptSyscall<NioAcceptSyscall<RawAcceptSyscall>>>
> = Lazy::new(Default::default);
} else {
static CHAIN: Lazy<AcceptSyscallFacade<NioAcceptSyscall<RawAcceptSyscall>>> =
Lazy::new(Default::default);
}
}
CHAIN.accept(fn_ptr, fd, address, address_len)
}

trait AcceptSyscall {
extern "C" fn accept(
&self,
Expand All @@ -32,6 +11,10 @@ trait AcceptSyscall {
) -> c_int;
}

impl_syscall!(AcceptSyscallFacade, IoUringAcceptSyscall, NioAcceptSyscall, RawAcceptSyscall,
accept(fd: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int
);

impl_facade!(AcceptSyscallFacade, AcceptSyscall,
accept(fd: c_int, address: *mut sockaddr, address_len: *mut socklen_t) -> c_int
);
Expand Down
26 changes: 4 additions & 22 deletions core/src/syscall/unix/accept4.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,6 @@
use libc::{sockaddr, socklen_t};
use once_cell::sync::Lazy;
use std::ffi::c_int;

#[must_use]
pub extern "C" fn accept4(
fn_ptr: Option<&extern "C" fn(c_int, *mut sockaddr, *mut socklen_t, c_int) -> c_int>,
fd: c_int,
addr: *mut sockaddr,
len: *mut socklen_t,
flg: c_int,
) -> c_int {
cfg_if::cfg_if! {
if #[cfg(all(target_os = "linux", feature = "io_uring"))] {
static CHAIN: Lazy<
Accept4SyscallFacade<IoUringAccept4Syscall<NioAccept4Syscall<RawAccept4Syscall>>>,
> = Lazy::new(Default::default);
} else {
static CHAIN: Lazy<Accept4SyscallFacade<NioAccept4Syscall<RawAccept4Syscall>>> =
Lazy::new(Default::default);
}
}
CHAIN.accept4(fn_ptr, fd, addr, len, flg)
}

trait Accept4Syscall {
extern "C" fn accept4(
&self,
Expand All @@ -34,6 +12,10 @@ trait Accept4Syscall {
) -> c_int;
}

impl_syscall!(Accept4SyscallFacade, IoUringAccept4Syscall, NioAccept4Syscall, RawAccept4Syscall,
accept4(fd: c_int, address: *mut sockaddr, address_len: *mut socklen_t, flg: c_int) -> c_int
);

impl_facade!(Accept4SyscallFacade, Accept4Syscall,
accept4(fd: c_int, address: *mut sockaddr, address_len: *mut socklen_t, flg: c_int) -> c_int
);
Expand Down
20 changes: 4 additions & 16 deletions core/src/syscall/unix/close.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
use crate::net::EventLoops;
use once_cell::sync::Lazy;
use std::ffi::c_int;

#[must_use]
pub extern "C" fn close(fn_ptr: Option<&extern "C" fn(c_int) -> c_int>, fd: c_int) -> c_int {
cfg_if::cfg_if! {
if #[cfg(all(target_os = "linux", feature = "io_uring"))] {
static CHAIN: Lazy<
CloseSyscallFacade<IoUringCloseSyscall<NioCloseSyscall<RawCloseSyscall>>>
> = Lazy::new(Default::default);
} else {
static CHAIN: Lazy<CloseSyscallFacade<NioCloseSyscall<RawCloseSyscall>>> =
Lazy::new(Default::default);
}
}
CHAIN.close(fn_ptr, fd)
}

trait CloseSyscall {
extern "C" fn close(&self, fn_ptr: Option<&extern "C" fn(c_int) -> c_int>, fd: c_int) -> c_int;
}

impl_syscall!(CloseSyscallFacade, IoUringCloseSyscall, NioCloseSyscall, RawCloseSyscall,
close(fd: c_int) -> c_int
);

impl_facade!(CloseSyscallFacade, CloseSyscall, close(fd: c_int) -> c_int);

impl_io_uring!(IoUringCloseSyscall, CloseSyscall, close(fd: c_int) -> c_int);
Expand Down
25 changes: 4 additions & 21 deletions core/src/syscall/unix/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,9 @@ use crate::common::now;
use crate::net::EventLoops;
use crate::syscall::{is_blocking, reset_errno, send_time_limit, set_blocking, set_errno, set_non_blocking};
use libc::{sockaddr, socklen_t};
use once_cell::sync::Lazy;
use std::ffi::{c_int, c_void};
use std::io::Error;

#[must_use]
pub extern "C" fn connect(
fn_ptr: Option<&extern "C" fn(c_int, *const sockaddr, socklen_t) -> c_int>,
socket: c_int,
address: *const sockaddr,
len: socklen_t,
) -> c_int {
cfg_if::cfg_if! {
if #[cfg(all(target_os = "linux", feature = "io_uring"))] {
static CHAIN: Lazy<
ConnectSyscallFacade<IoUringConnectSyscall<NioConnectSyscall<RawConnectSyscall>>>
> = Lazy::new(Default::default);
} else {
static CHAIN: Lazy<ConnectSyscallFacade<NioConnectSyscall<RawConnectSyscall>>> =
Lazy::new(Default::default);
}
}
CHAIN.connect(fn_ptr, socket, address, len)
}

trait ConnectSyscall {
extern "C" fn connect(
&self,
Expand All @@ -36,6 +15,10 @@ trait ConnectSyscall {
) -> c_int;
}

impl_syscall!(ConnectSyscallFacade, IoUringConnectSyscall, NioConnectSyscall, RawConnectSyscall,
connect(fd: c_int, address: *const sockaddr, len: socklen_t) -> c_int
);

impl_facade!(ConnectSyscallFacade, ConnectSyscall,
connect(fd: c_int, address: *const sockaddr, len: socklen_t) -> c_int
);
Expand Down
19 changes: 2 additions & 17 deletions core/src/syscall/unix/fsync.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
use once_cell::sync::Lazy;
use std::ffi::c_int;

#[must_use]
pub extern "C" fn fsync(
fn_ptr: Option<&extern "C" fn(c_int) -> c_int>,
fd: c_int,
) -> c_int {
cfg_if::cfg_if! {
if #[cfg(all(target_os = "linux", feature = "io_uring"))] {
static CHAIN: Lazy<FsyncSyscallFacade<IoUringFsyncSyscall<RawFsyncSyscall>>> =
Lazy::new(Default::default);
} else {
static CHAIN: Lazy<FsyncSyscallFacade<RawFsyncSyscall>> = Lazy::new(Default::default);
}
}
CHAIN.fsync(fn_ptr, fd)
}

trait FsyncSyscall {
extern "C" fn fsync(
&self,
Expand All @@ -25,6 +8,8 @@ trait FsyncSyscall {
) -> c_int;
}

impl_syscall2!(FsyncSyscallFacade, IoUringFsyncSyscall, RawFsyncSyscall, fsync(fd: c_int) -> c_int);

impl_facade!(FsyncSyscallFacade, FsyncSyscall, fsync(fd: c_int) -> c_int);

impl_io_uring!(IoUringFsyncSyscall, FsyncSyscall, fsync(fd: c_int) -> c_int);
Expand Down
15 changes: 4 additions & 11 deletions core/src/syscall/unix/link.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
use std::ffi::{c_char, c_int};
use once_cell::sync::Lazy;

#[must_use]
pub extern "C" fn link(
fn_ptr: Option<&extern "C" fn(*const c_char, *const c_char) -> c_int>,
src: *const c_char,
dst: *const c_char
) -> c_int{
static CHAIN: Lazy<LinkSyscallFacade<RawLinkSyscall>> = Lazy::new(Default::default);
CHAIN.link(fn_ptr, src, dst)
}

trait LinkSyscall {
extern "C" fn link(
Expand All @@ -20,6 +9,10 @@ trait LinkSyscall {
) -> c_int;
}

impl_syscall!(LinkSyscallFacade, RawLinkSyscall,
link(src: *const c_char, dst: *const c_char) -> c_int
);

impl_facade!(LinkSyscallFacade, LinkSyscall,
link(src: *const c_char, dst: *const c_char) -> c_int
);
Expand Down
13 changes: 2 additions & 11 deletions core/src/syscall/unix/listen.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
use once_cell::sync::Lazy;
use std::ffi::c_int;

#[must_use]
pub extern "C" fn listen(
fn_ptr: Option<&extern "C" fn(c_int, c_int) -> c_int>,
fd: c_int,
backlog: c_int,
) -> c_int {
static CHAIN: Lazy<ListenSyscallFacade<RawListenSyscall>> = Lazy::new(Default::default);
CHAIN.listen(fn_ptr, fd, backlog)
}

trait ListenSyscall {
extern "C" fn listen(
&self,
Expand All @@ -20,6 +9,8 @@ trait ListenSyscall {
) -> c_int;
}

impl_syscall!(ListenSyscallFacade, RawListenSyscall, listen(fd: c_int, backlog: c_int) -> c_int);

impl_facade!(ListenSyscallFacade, ListenSyscall, listen(fd: c_int, backlog: c_int) -> c_int);

impl_raw!(RawListenSyscall, ListenSyscall, listen(fd: c_int, backlog: c_int) -> c_int);
16 changes: 4 additions & 12 deletions core/src/syscall/unix/lseek.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
use libc::off_t;
use std::ffi::c_int;
use once_cell::sync::Lazy;

#[must_use]
pub extern "C" fn lseek(
fn_ptr: Option<&extern "C" fn(c_int, off_t, c_int) -> off_t>,
fd: c_int,
offset: off_t,
whence: c_int,
) -> off_t{
static CHAIN: Lazy<LseekSyscallFacade<RawLseekSyscall>> = Lazy::new(Default::default);
CHAIN.lseek(fn_ptr, fd, offset,whence)
}

trait LseekSyscall {
extern "C" fn lseek(
Expand All @@ -23,6 +11,10 @@ trait LseekSyscall {
) -> off_t;
}

impl_syscall!(LseekSyscallFacade, RawLseekSyscall,
lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t
);

impl_facade!(LseekSyscallFacade, LseekSyscall,
lseek(fd: c_int, offset: off_t, whence: c_int) -> off_t
);
Expand Down
15 changes: 4 additions & 11 deletions core/src/syscall/unix/mkdir.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
use libc::mode_t;
use once_cell::sync::Lazy;
use std::ffi::{c_char, c_int};

#[must_use]
pub extern "C" fn mkdir(
fn_ptr: Option<&extern "C" fn(*const c_char, mode_t) -> c_int>,
path: *const c_char,
mode: mode_t,
) -> c_int {
static CHAIN: Lazy<MkdirSyscallFacade<RawMkdirSyscall>> = Lazy::new(Default::default);
CHAIN.mkdir(fn_ptr, path, mode)
}

trait MkdirSyscall {
extern "C" fn mkdir(
&self,
Expand All @@ -21,6 +10,10 @@ trait MkdirSyscall {
) -> c_int;
}

impl_syscall!(MkdirSyscallFacade, RawMkdirSyscall,
mkdir(path: *const c_char, mode: mode_t) -> c_int
);

impl_facade!(MkdirSyscallFacade, MkdirSyscall,
mkdir(path: *const c_char, mode: mode_t) -> c_int
);
Expand Down
23 changes: 4 additions & 19 deletions core/src/syscall/unix/mkdirat.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
use libc::mode_t;
use once_cell::sync::Lazy;
use std::ffi::{c_char, c_int};

#[must_use]
pub extern "C" fn mkdirat(
fn_ptr: Option<&extern "C" fn(c_int, *const c_char, mode_t) -> c_int>,
dirfd: c_int,
pathname: *const c_char,
mode: mode_t,
) -> c_int {
cfg_if::cfg_if! {
if #[cfg(all(target_os = "linux", feature = "io_uring"))] {
static CHAIN: Lazy<MkdiratSyscallFacade<IoUringMkdiratSyscall<RawMkdiratSyscall>>> =
Lazy::new(Default::default);
} else {
static CHAIN: Lazy<MkdiratSyscallFacade<RawMkdiratSyscall>> = Lazy::new(Default::default);
}
}
CHAIN.mkdirat(fn_ptr, dirfd, pathname, mode)
}

trait MkdiratSyscall {
extern "C" fn mkdirat(
&self,
Expand All @@ -30,6 +11,10 @@ trait MkdiratSyscall {
) -> c_int;
}

impl_syscall2!(MkdiratSyscallFacade, IoUringMkdiratSyscall, RawMkdiratSyscall,
mkdirat(dirfd: c_int, pathname: *const c_char, mode: mode_t) -> c_int
);

impl_facade!(MkdiratSyscallFacade, MkdiratSyscall,
mkdirat(dirfd: c_int, pathname: *const c_char, mode: mode_t) -> c_int
);
Expand Down
Loading
Loading