From 661970f62f5897bc0cd5fdca7e087ba8a98a8fa1 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 27 Oct 2017 12:30:52 +0000 Subject: [PATCH] unix: add Poll function on Solaris Tested with TestPoll extracted from syscall_linux_test.go. Now that Poll is supported on all unix flavors, TestPoll can be moved to syscall_unix_test.go in a successive CL. Change-Id: Ibd5ff3f45198008464522c3b165f2af7865ce81e Reviewed-on: https://go-review.googlesource.com/73881 Reviewed-by: Ian Lance Taylor --- unix/syscall_solaris.go | 9 +++++++++ unix/types_solaris.go | 18 ++++++++++++++++++ unix/zsyscall_solaris_amd64.go | 12 ++++++++++++ unix/ztypes_solaris_amd64.go | 19 +++++++++++++++++++ 4 files changed, 58 insertions(+) diff --git a/unix/syscall_solaris.go b/unix/syscall_solaris.go index 80be7902..3ab9e07c 100644 --- a/unix/syscall_solaris.go +++ b/unix/syscall_solaris.go @@ -578,6 +578,15 @@ func IoctlGetTermio(fd int, req uint) (*Termio, error) { return &value, err } +//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 */ diff --git a/unix/types_solaris.go b/unix/types_solaris.go index 6d746140..f7771554 100644 --- a/unix/types_solaris.go +++ b/unix/types_solaris.go @@ -24,6 +24,7 @@ package unix #include #include #include +#include #include #include #include @@ -263,3 +264,20 @@ type Termios C.struct_termios type Termio C.struct_termio type Winsize C.struct_winsize + +// 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 +) diff --git a/unix/zsyscall_solaris_amd64.go b/unix/zsyscall_solaris_amd64.go index 98b26655..1d452764 100644 --- a/unix/zsyscall_solaris_amd64.go +++ b/unix/zsyscall_solaris_amd64.go @@ -29,6 +29,7 @@ import ( //go:cgo_import_dynamic libc___major __major "libc.so" //go:cgo_import_dynamic libc___minor __minor "libc.so" //go:cgo_import_dynamic libc_ioctl ioctl "libc.so" +//go:cgo_import_dynamic libc_poll poll "libc.so" //go:cgo_import_dynamic libc_access access "libc.so" //go:cgo_import_dynamic libc_adjtime adjtime "libc.so" //go:cgo_import_dynamic libc_chdir chdir "libc.so" @@ -153,6 +154,7 @@ import ( //go:linkname proc__major libc___major //go:linkname proc__minor libc___minor //go:linkname procioctl libc_ioctl +//go:linkname procpoll libc_poll //go:linkname procAccess libc_access //go:linkname procAdjtime libc_adjtime //go:linkname procChdir libc_chdir @@ -278,6 +280,7 @@ var ( proc__major, proc__minor, procioctl, + procpoll, procAccess, procAdjtime, procChdir, @@ -557,6 +560,15 @@ func ioctl(fd int, req uint, arg uintptr) (err error) { return } +func poll(fds *PollFd, nfds int, timeout int) (n int, err error) { + r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procpoll)), 3, uintptr(unsafe.Pointer(fds)), uintptr(nfds), uintptr(timeout), 0, 0, 0) + n = int(r0) + if e1 != 0 { + err = e1 + } + return +} + func Access(path string, mode uint32) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) diff --git a/unix/ztypes_solaris_amd64.go b/unix/ztypes_solaris_amd64.go index a979a33d..c2280a57 100644 --- a/unix/ztypes_solaris_amd64.go +++ b/unix/ztypes_solaris_amd64.go @@ -438,3 +438,22 @@ type Winsize struct { Xpixel uint16 Ypixel uint16 } + +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 +)