mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
feat(unix): add poll
This commit is contained in:
@@ -432,6 +432,18 @@ AT_FDCWD :: ~uintptr(99) /* -100 */
|
|||||||
AT_REMOVEDIR :: uintptr(0x200)
|
AT_REMOVEDIR :: uintptr(0x200)
|
||||||
AT_SYMLINK_NOFOLLOW :: uintptr(0x100)
|
AT_SYMLINK_NOFOLLOW :: uintptr(0x100)
|
||||||
|
|
||||||
|
pollfd :: struct {
|
||||||
|
fd: c.int,
|
||||||
|
events: c.short,
|
||||||
|
revents: c.short,
|
||||||
|
}
|
||||||
|
|
||||||
|
nfds_t :: distinct c.uint
|
||||||
|
|
||||||
|
sigset_t :: struct {
|
||||||
|
__val: [16]c.ulong,
|
||||||
|
}
|
||||||
|
|
||||||
foreign libc {
|
foreign libc {
|
||||||
@(link_name="__errno_location") __errno_location :: proc() -> ^int ---
|
@(link_name="__errno_location") __errno_location :: proc() -> ^int ---
|
||||||
|
|
||||||
@@ -1087,3 +1099,27 @@ fcntl :: proc(fd: int, cmd: int, arg: int) -> (int, Errno) {
|
|||||||
}
|
}
|
||||||
return result, ERROR_NONE
|
return result, ERROR_NONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// select :: proc(nfds: int, readfds: ^fd_set, writefds: ^fd_set, exceptfds: ^fd_set, timeout: ^timeval) -> (int, Errno) {
|
||||||
|
// result := unix.sys_select(nfds, readfds, writefds, exceptfds, timeout)
|
||||||
|
// if result < 0 {
|
||||||
|
// return 0, _get_errno(result)
|
||||||
|
// }
|
||||||
|
// return result, ERROR_NONE
|
||||||
|
// }
|
||||||
|
|
||||||
|
poll :: proc(fds: [^]pollfd, nfds: nfds_t, timeout: int) -> (int, Errno) {
|
||||||
|
result := unix.sys_poll(fds, uint(nfds), timeout)
|
||||||
|
if result < 0 {
|
||||||
|
return 0, _get_errno(result)
|
||||||
|
}
|
||||||
|
return result, ERROR_NONE
|
||||||
|
}
|
||||||
|
|
||||||
|
ppoll :: proc(fds: [^]pollfd, nfds: nfds_t, timeout: ^unix.timespec, sigmask: ^sigset_t) -> (int, Errno) {
|
||||||
|
result := unix.sys_ppoll(fds, uint(nfds), timeout, sigmask, size_of(sigset_t))
|
||||||
|
if result < 0 {
|
||||||
|
return 0, _get_errno(result)
|
||||||
|
}
|
||||||
|
return result, ERROR_NONE
|
||||||
|
}
|
||||||
|
|||||||
@@ -1567,6 +1567,23 @@ MADV_HWPOISON :: 100
|
|||||||
// pipe2 flags
|
// pipe2 flags
|
||||||
O_CLOEXEC :: 0o2000000
|
O_CLOEXEC :: 0o2000000
|
||||||
|
|
||||||
|
// poll events
|
||||||
|
POLLIN :: 0x0001
|
||||||
|
POLLPRI :: 0x0002
|
||||||
|
POLLOUT :: 0x0004
|
||||||
|
POLLERR :: 0x0008
|
||||||
|
POLLHUP :: 0x0010
|
||||||
|
POLLNVAL :: 0x0020
|
||||||
|
POLLRDNORM :: 0x0040
|
||||||
|
POLLRDBAND :: 0x0080
|
||||||
|
POLLWRNORM :: 0x0100
|
||||||
|
POLLWRBAND :: 0x0200
|
||||||
|
POLLMSG :: 0x0400
|
||||||
|
POLLREMOVE :: 0x1000
|
||||||
|
POLLRDHUP :: 0x2000
|
||||||
|
POLLFREE :: 0x4000
|
||||||
|
POLL_BUSY_LOOP :: 0x8000
|
||||||
|
|
||||||
// perf event data
|
// perf event data
|
||||||
Perf_Sample :: struct #raw_union {
|
Perf_Sample :: struct #raw_union {
|
||||||
period: u64,
|
period: u64,
|
||||||
@@ -2057,6 +2074,18 @@ sys_fcntl :: proc "contextless" (fd: int, cmd: int, arg: int) -> int {
|
|||||||
return int(intrinsics.syscall(SYS_fcntl, uintptr(fd), uintptr(cmd), uintptr(arg)))
|
return int(intrinsics.syscall(SYS_fcntl, uintptr(fd), uintptr(cmd), uintptr(arg)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sys_select :: proc "contextless" (nfds: int, readfds, writefds, exceptfds: rawptr, timeout: rawptr) -> int {
|
||||||
|
return int(intrinsics.syscall(SYS_select, uintptr(nfds), uintptr(readfds), uintptr(writefds), uintptr(exceptfds), uintptr(timeout)))
|
||||||
|
}
|
||||||
|
|
||||||
|
sys_poll :: proc "contextless" (fds: rawptr, nfds: uint, timeout: int) -> int {
|
||||||
|
return int(intrinsics.syscall(SYS_poll, uintptr(fds), uintptr(nfds), uintptr(timeout)))
|
||||||
|
}
|
||||||
|
|
||||||
|
sys_ppoll :: proc "contextless" (fds: rawptr, nfds: uint, timeout: rawptr, sigmask: rawptr, sigsetsize: uint) -> int {
|
||||||
|
return int(intrinsics.syscall(SYS_ppoll, uintptr(fds), uintptr(nfds), uintptr(timeout), uintptr(sigmask), uintptr(sigsetsize)))
|
||||||
|
}
|
||||||
|
|
||||||
get_errno :: proc "contextless" (res: int) -> i32 {
|
get_errno :: proc "contextless" (res: int) -> i32 {
|
||||||
if res < 0 && res > -4096 {
|
if res < 0 && res > -4096 {
|
||||||
return i32(-res)
|
return i32(-res)
|
||||||
|
|||||||
Reference in New Issue
Block a user