unix: add Poll for linux
Change-Id: I273bd852f85d204694872a1615be51dc027b97ee
Reviewed-on: https://go-review.googlesource.com/23661
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go
index 9ca104c..a4b3542 100644
--- a/unix/syscall_linux.go
+++ b/unix/syscall_linux.go
@@ -60,6 +60,15 @@
return openat(dirfd, path, flags|O_LARGEFILE, mode)
}
+//sys poll(fds *PollFd, nfd 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)
+}
+
//sys readlinkat(dirfd int, path string, buf []byte) (n int, err error)
func Readlink(path string, buf []byte) (n int, err error) {
@@ -1043,7 +1052,6 @@
// Newfstatat
// Nfsservctl
// Personality
-// Poll
// Ppoll
// Pselect6
// Ptrace
diff --git a/unix/syscall_linux_test.go b/unix/syscall_linux_test.go
index 2238b65..386666f 100644
--- a/unix/syscall_linux_test.go
+++ b/unix/syscall_linux_test.go
@@ -15,6 +15,45 @@
"golang.org/x/sys/unix"
)
+func TestPoll(t *testing.T) {
+ err := unix.Mkfifo("fifo", 0666)
+ if err != nil {
+ t.Errorf("Poll: failed to create FIFO: %v", err)
+ return
+ }
+ defer os.Remove("fifo")
+
+ f, err := os.OpenFile("fifo", os.O_RDWR, 0666)
+ if err != nil {
+ t.Errorf("Poll: failed to open FIFO: %v", err)
+ return
+ }
+ defer f.Close()
+
+ const timeout = 100
+
+ ok := make(chan bool, 1)
+ go func() {
+ select {
+ case <-time.After(10 * timeout * time.Millisecond):
+ t.Errorf("Poll: failed to timeout after %d milliseconds", 10*timeout)
+ case <-ok:
+ }
+ }()
+
+ fds := []unix.PollFd{{Fd: int32(f.Fd()), Events: unix.POLLIN}}
+ n, err := unix.Poll(fds, timeout)
+ ok <- true
+ if err != nil {
+ t.Errorf("Poll: unexpected error: %v", err)
+ return
+ }
+ if n != 0 {
+ t.Errorf("Poll: wrong number of events: got %v, expected %v", n, 0)
+ return
+ }
+}
+
func TestTime(t *testing.T) {
var ut unix.Time_t
ut2, err := unix.Time(&ut)
diff --git a/unix/types_linux.go b/unix/types_linux.go
index d004b4a..10cbd09 100644
--- a/unix/types_linux.go
+++ b/unix/types_linux.go
@@ -24,6 +24,7 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netpacket/packet.h>
+#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <sys/epoll.h>
@@ -430,6 +431,18 @@
AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW
)
+type PollFd C.struct_pollfd
+
+const (
+ POLLIN = C.POLLIN
+ POLLPRI = C.POLLPRI
+ POLLOUT = C.POLLOUT
+ POLLRDHUP = C.POLLRDHUP
+ POLLERR = C.POLLERR
+ POLLHUP = C.POLLHUP
+ POLLNVAL = C.POLLNVAL
+)
+
// Terminal handling
type Termios C.termios_t
diff --git a/unix/zsyscall_linux_386.go b/unix/zsyscall_linux_386.go
index 749f3e4..b7aa178 100644
--- a/unix/zsyscall_linux_386.go
+++ b/unix/zsyscall_linux_386.go
@@ -53,6 +53,17 @@
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+func poll(fds *PollFd, nfd int, timeout int) (n int, err error) {
+ r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfd), 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 readlinkat(dirfd int, path string, buf []byte) (n int, err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
diff --git a/unix/zsyscall_linux_amd64.go b/unix/zsyscall_linux_amd64.go
index 1096aa5..be4f62b 100644
--- a/unix/zsyscall_linux_amd64.go
+++ b/unix/zsyscall_linux_amd64.go
@@ -53,6 +53,17 @@
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+func poll(fds *PollFd, nfd int, timeout int) (n int, err error) {
+ r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfd), 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 readlinkat(dirfd int, path string, buf []byte) (n int, err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
diff --git a/unix/zsyscall_linux_arm.go b/unix/zsyscall_linux_arm.go
index 9066e1c..9f77001 100644
--- a/unix/zsyscall_linux_arm.go
+++ b/unix/zsyscall_linux_arm.go
@@ -53,6 +53,17 @@
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+func poll(fds *PollFd, nfd int, timeout int) (n int, err error) {
+ r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfd), 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 readlinkat(dirfd int, path string, buf []byte) (n int, err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
diff --git a/unix/zsyscall_linux_arm64.go b/unix/zsyscall_linux_arm64.go
index 5b91612..fadbe4b 100644
--- a/unix/zsyscall_linux_arm64.go
+++ b/unix/zsyscall_linux_arm64.go
@@ -53,6 +53,17 @@
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+func poll(fds *PollFd, nfd int, timeout int) (n int, err error) {
+ r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfd), 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 readlinkat(dirfd int, path string, buf []byte) (n int, err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
diff --git a/unix/zsyscall_linux_mips64.go b/unix/zsyscall_linux_mips64.go
index 738c830..0389f1f 100644
--- a/unix/zsyscall_linux_mips64.go
+++ b/unix/zsyscall_linux_mips64.go
@@ -53,6 +53,17 @@
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+func poll(fds *PollFd, nfd int, timeout int) (n int, err error) {
+ r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfd), 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 readlinkat(dirfd int, path string, buf []byte) (n int, err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
diff --git a/unix/zsyscall_linux_mips64le.go b/unix/zsyscall_linux_mips64le.go
index 2a03578..8695188 100644
--- a/unix/zsyscall_linux_mips64le.go
+++ b/unix/zsyscall_linux_mips64le.go
@@ -53,6 +53,17 @@
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+func poll(fds *PollFd, nfd int, timeout int) (n int, err error) {
+ r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfd), 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 readlinkat(dirfd int, path string, buf []byte) (n int, err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
diff --git a/unix/zsyscall_linux_ppc64.go b/unix/zsyscall_linux_ppc64.go
index 4bd18dc..2401976 100644
--- a/unix/zsyscall_linux_ppc64.go
+++ b/unix/zsyscall_linux_ppc64.go
@@ -53,6 +53,17 @@
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+func poll(fds *PollFd, nfd int, timeout int) (n int, err error) {
+ r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfd), 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 readlinkat(dirfd int, path string, buf []byte) (n int, err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
diff --git a/unix/zsyscall_linux_ppc64le.go b/unix/zsyscall_linux_ppc64le.go
index fbb4351..d6d62ea 100644
--- a/unix/zsyscall_linux_ppc64le.go
+++ b/unix/zsyscall_linux_ppc64le.go
@@ -53,6 +53,17 @@
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+func poll(fds *PollFd, nfd int, timeout int) (n int, err error) {
+ r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfd), 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 readlinkat(dirfd int, path string, buf []byte) (n int, err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
diff --git a/unix/zsyscall_linux_s390x.go b/unix/zsyscall_linux_s390x.go
index f8aa91f..3ff6a93 100644
--- a/unix/zsyscall_linux_s390x.go
+++ b/unix/zsyscall_linux_s390x.go
@@ -53,6 +53,17 @@
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+func poll(fds *PollFd, nfd int, timeout int) (n int, err error) {
+ r0, _, e1 := Syscall(SYS_POLL, uintptr(unsafe.Pointer(fds)), uintptr(nfd), 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 readlinkat(dirfd int, path string, buf []byte) (n int, err error) {
var _p0 *byte
_p0, err = BytePtrFromString(path)
diff --git a/unix/ztypes_linux_386.go b/unix/ztypes_linux_386.go
index fb1257a..b684543 100644
--- a/unix/ztypes_linux_386.go
+++ b/unix/ztypes_linux_386.go
@@ -595,6 +595,22 @@
AT_SYMLINK_NOFOLLOW = 0x100
)
+type PollFd struct {
+ Fd int32
+ Events int16
+ Revents int16
+}
+
+const (
+ POLLIN = 0x1
+ POLLPRI = 0x2
+ POLLOUT = 0x4
+ POLLRDHUP = 0x2000
+ POLLERR = 0x8
+ POLLHUP = 0x10
+ POLLNVAL = 0x20
+)
+
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_amd64.go b/unix/ztypes_linux_amd64.go
index 34edb36..4633818 100644
--- a/unix/ztypes_linux_amd64.go
+++ b/unix/ztypes_linux_amd64.go
@@ -613,6 +613,22 @@
AT_SYMLINK_NOFOLLOW = 0x100
)
+type PollFd struct {
+ Fd int32
+ Events int16
+ Revents int16
+}
+
+const (
+ POLLIN = 0x1
+ POLLPRI = 0x2
+ POLLOUT = 0x4
+ POLLRDHUP = 0x2000
+ POLLERR = 0x8
+ POLLHUP = 0x10
+ POLLNVAL = 0x20
+)
+
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_arm.go b/unix/ztypes_linux_arm.go
index 0fef350..42d9ae4 100644
--- a/unix/ztypes_linux_arm.go
+++ b/unix/ztypes_linux_arm.go
@@ -575,6 +575,22 @@
AT_SYMLINK_NOFOLLOW = 0x100
)
+type PollFd struct {
+ Fd int32
+ Events int16
+ Revents int16
+}
+
+const (
+ POLLIN = 0x1
+ POLLPRI = 0x2
+ POLLOUT = 0x4
+ POLLRDHUP = 0x2000
+ POLLERR = 0x8
+ POLLHUP = 0x10
+ POLLNVAL = 0x20
+)
+
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_arm64.go b/unix/ztypes_linux_arm64.go
index 28b7cd4..b30d472 100644
--- a/unix/ztypes_linux_arm64.go
+++ b/unix/ztypes_linux_arm64.go
@@ -592,6 +592,22 @@
AT_SYMLINK_NOFOLLOW = 0x100
)
+type PollFd struct {
+ Fd int32
+ Events int16
+ Revents int16
+}
+
+const (
+ POLLIN = 0x1
+ POLLPRI = 0x2
+ POLLOUT = 0x4
+ POLLRDHUP = 0x2000
+ POLLERR = 0x8
+ POLLHUP = 0x10
+ POLLNVAL = 0x20
+)
+
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_mips64.go b/unix/ztypes_linux_mips64.go
index 8fe5af2..c247b31 100644
--- a/unix/ztypes_linux_mips64.go
+++ b/unix/ztypes_linux_mips64.go
@@ -596,6 +596,22 @@
AT_SYMLINK_NOFOLLOW = 0x100
)
+type PollFd struct {
+ Fd int32
+ Events int16
+ Revents int16
+}
+
+const (
+ POLLIN = 0x1
+ POLLPRI = 0x2
+ POLLOUT = 0x4
+ POLLRDHUP = 0x2000
+ POLLERR = 0x8
+ POLLHUP = 0x10
+ POLLNVAL = 0x20
+)
+
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_mips64le.go b/unix/ztypes_linux_mips64le.go
index df16e83..9f6ae97 100644
--- a/unix/ztypes_linux_mips64le.go
+++ b/unix/ztypes_linux_mips64le.go
@@ -596,6 +596,22 @@
AT_SYMLINK_NOFOLLOW = 0x100
)
+type PollFd struct {
+ Fd int32
+ Events int16
+ Revents int16
+}
+
+const (
+ POLLIN = 0x1
+ POLLPRI = 0x2
+ POLLOUT = 0x4
+ POLLRDHUP = 0x2000
+ POLLERR = 0x8
+ POLLHUP = 0x10
+ POLLNVAL = 0x20
+)
+
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_ppc64.go b/unix/ztypes_linux_ppc64.go
index d110540..0f94f79 100644
--- a/unix/ztypes_linux_ppc64.go
+++ b/unix/ztypes_linux_ppc64.go
@@ -602,6 +602,22 @@
AT_SYMLINK_NOFOLLOW = 0x100
)
+type PollFd struct {
+ Fd int32
+ Events int16
+ Revents int16
+}
+
+const (
+ POLLIN = 0x1
+ POLLPRI = 0x2
+ POLLOUT = 0x4
+ POLLRDHUP = 0x2000
+ POLLERR = 0x8
+ POLLHUP = 0x10
+ POLLNVAL = 0x20
+)
+
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_ppc64le.go b/unix/ztypes_linux_ppc64le.go
index 8e25c9f..9c21ecf 100644
--- a/unix/ztypes_linux_ppc64le.go
+++ b/unix/ztypes_linux_ppc64le.go
@@ -602,6 +602,22 @@
AT_SYMLINK_NOFOLLOW = 0x100
)
+type PollFd struct {
+ Fd int32
+ Events int16
+ Revents int16
+}
+
+const (
+ POLLIN = 0x1
+ POLLPRI = 0x2
+ POLLOUT = 0x4
+ POLLRDHUP = 0x2000
+ POLLERR = 0x8
+ POLLHUP = 0x10
+ POLLNVAL = 0x20
+)
+
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_s390x.go b/unix/ztypes_linux_s390x.go
index 268e373..2f808ec 100644
--- a/unix/ztypes_linux_s390x.go
+++ b/unix/ztypes_linux_s390x.go
@@ -617,6 +617,22 @@
AT_SYMLINK_NOFOLLOW = 0x100
)
+type PollFd struct {
+ Fd int32
+ Events int16
+ Revents int16
+}
+
+const (
+ POLLIN = 0x1
+ POLLPRI = 0x2
+ POLLOUT = 0x4
+ POLLRDHUP = 0x2000
+ POLLERR = 0x8
+ POLLHUP = 0x10
+ POLLNVAL = 0x20
+)
+
type Termios struct {
Iflag uint32
Oflag uint32