From 0649f9fe46d917da5591af4d4784b6badd31d7e5 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 26 Oct 2017 09:01:12 +0000 Subject: [PATCH] unix: add Poll function on NetBSD Tested with TestPoll extracted from syscall_linux_test.go. Once Poll is supported on all OSes this test can be moved to syscall_unix_test.go. Change-Id: I61ec50c5ea7d6db43f7688ed925d6ed26a6bbc3a Reviewed-on: https://go-review.googlesource.com/73650 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- unix/syscall_netbsd.go | 10 +++++++++- unix/types_netbsd.go | 18 ++++++++++++++++++ unix/zsyscall_netbsd_386.go | 11 +++++++++++ unix/zsyscall_netbsd_amd64.go | 11 +++++++++++ unix/zsyscall_netbsd_arm.go | 11 +++++++++++ unix/ztypes_netbsd_386.go | 23 +++++++++++++++++++++-- unix/ztypes_netbsd_amd64.go | 23 +++++++++++++++++++++-- unix/ztypes_netbsd_arm.go | 23 +++++++++++++++++++++-- 8 files changed, 123 insertions(+), 7 deletions(-) diff --git a/unix/syscall_netbsd.go b/unix/syscall_netbsd.go index e1296684..f0370bfa 100644 --- a/unix/syscall_netbsd.go +++ b/unix/syscall_netbsd.go @@ -124,6 +124,15 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e return -1, ENOSYS } +//sys poll(fds *PollFd, nfds int, timeout int) (n int, err error) + +func Poll(fds []PollFd, timeout int) (n int, err error) { + if len(fds) == 0 { + return poll(nil, 0, timeout) + } + return poll(&fds[0], len(fds), timeout) +} + /* * Exposed directly */ @@ -422,7 +431,6 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e // ntp_adjtime // pmc_control // pmc_get_info -// poll // pollts // preadv // profil diff --git a/unix/types_netbsd.go b/unix/types_netbsd.go index cb95c80a..9097245a 100644 --- a/unix/types_netbsd.go +++ b/unix/types_netbsd.go @@ -17,6 +17,7 @@ package unix #define KERNEL #include #include +#include #include #include #include @@ -234,6 +235,23 @@ const ( AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW ) +// poll + +type PollFd C.struct_pollfd + +const ( + POLLERR = C.POLLERR + POLLHUP = C.POLLHUP + POLLIN = C.POLLIN + POLLNVAL = C.POLLNVAL + POLLOUT = C.POLLOUT + POLLPRI = C.POLLPRI + POLLRDBAND = C.POLLRDBAND + POLLRDNORM = C.POLLRDNORM + POLLWRBAND = C.POLLWRBAND + POLLWRNORM = C.POLLWRNORM +) + // Sysctl type Sysctlnode C.struct_sysctlnode diff --git a/unix/zsyscall_netbsd_386.go b/unix/zsyscall_netbsd_386.go index db99fd0c..32d9656b 100644 --- a/unix/zsyscall_netbsd_386.go +++ b/unix/zsyscall_netbsd_386.go @@ -395,6 +395,17 @@ func getdents(fd int, buf []byte) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Access(path string, mode uint32) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) diff --git a/unix/zsyscall_netbsd_amd64.go b/unix/zsyscall_netbsd_amd64.go index 7b6c2c87..6d6e10a9 100644 --- a/unix/zsyscall_netbsd_amd64.go +++ b/unix/zsyscall_netbsd_amd64.go @@ -395,6 +395,17 @@ func getdents(fd int, buf []byte) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Access(path string, mode uint32) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) diff --git a/unix/zsyscall_netbsd_arm.go b/unix/zsyscall_netbsd_arm.go index 0f4cc3b5..936a0c59 100644 --- a/unix/zsyscall_netbsd_arm.go +++ b/unix/zsyscall_netbsd_arm.go @@ -395,6 +395,17 @@ func getdents(fd int, buf []byte) (n int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout)) + n = int(r0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Access(path string, mode uint32) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) diff --git a/unix/ztypes_netbsd_386.go b/unix/ztypes_netbsd_386.go index 42f99c0a..dfe446bf 100644 --- a/unix/ztypes_netbsd_386.go +++ b/unix/ztypes_netbsd_386.go @@ -1,5 +1,5 @@ -// Created by cgo -godefs - DO NOT EDIT -// cgo -godefs types_netbsd.go +// cgo -godefs types_netbsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. // +build 386,netbsd @@ -387,6 +387,25 @@ const ( AT_SYMLINK_NOFOLLOW = 0x200 ) +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + type Sysctlnode struct { Flags uint32 Num int32 diff --git a/unix/ztypes_netbsd_amd64.go b/unix/ztypes_netbsd_amd64.go index ff290ba0..1498c23c 100644 --- a/unix/ztypes_netbsd_amd64.go +++ b/unix/ztypes_netbsd_amd64.go @@ -1,5 +1,5 @@ -// Created by cgo -godefs - DO NOT EDIT -// cgo -godefs types_netbsd.go +// cgo -godefs types_netbsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. // +build amd64,netbsd @@ -394,6 +394,25 @@ const ( AT_SYMLINK_NOFOLLOW = 0x200 ) +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + type Sysctlnode struct { Flags uint32 Num int32 diff --git a/unix/ztypes_netbsd_arm.go b/unix/ztypes_netbsd_arm.go index 66dbd7c0..d6711ce1 100644 --- a/unix/ztypes_netbsd_arm.go +++ b/unix/ztypes_netbsd_arm.go @@ -1,5 +1,5 @@ -// Created by cgo -godefs - DO NOT EDIT -// cgo -godefs types_netbsd.go +// cgo -godefs types_netbsd.go | go run mkpost.go +// Code generated by the command above; see README.md. DO NOT EDIT. // +build arm,netbsd @@ -392,6 +392,25 @@ const ( AT_SYMLINK_NOFOLLOW = 0x200 ) +type PollFd struct { + Fd int32 + Events int16 + Revents int16 +} + +const ( + POLLERR = 0x8 + POLLHUP = 0x10 + POLLIN = 0x1 + POLLNVAL = 0x20 + POLLOUT = 0x4 + POLLPRI = 0x2 + POLLRDBAND = 0x80 + POLLRDNORM = 0x40 + POLLWRBAND = 0x100 + POLLWRNORM = 0x4 +) + type Sysctlnode struct { Flags uint32 Num int32