mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-01 06:46:44 -04:00
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 <iant@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
b98136db33
commit
661970f62f
@@ -578,6 +578,15 @@ func IoctlGetTermio(fd int, req uint) (*Termio, error) {
|
|||||||
return &value, err
|
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
|
* Exposed directly
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ package unix
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <poll.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <termio.h>
|
#include <termio.h>
|
||||||
@@ -263,3 +264,20 @@ type Termios C.struct_termios
|
|||||||
type Termio C.struct_termio
|
type Termio C.struct_termio
|
||||||
|
|
||||||
type Winsize C.struct_winsize
|
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
|
||||||
|
)
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import (
|
|||||||
//go:cgo_import_dynamic libc___major __major "libc.so"
|
//go:cgo_import_dynamic libc___major __major "libc.so"
|
||||||
//go:cgo_import_dynamic libc___minor __minor "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_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_access access "libc.so"
|
||||||
//go:cgo_import_dynamic libc_adjtime adjtime "libc.so"
|
//go:cgo_import_dynamic libc_adjtime adjtime "libc.so"
|
||||||
//go:cgo_import_dynamic libc_chdir chdir "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__major libc___major
|
||||||
//go:linkname proc__minor libc___minor
|
//go:linkname proc__minor libc___minor
|
||||||
//go:linkname procioctl libc_ioctl
|
//go:linkname procioctl libc_ioctl
|
||||||
|
//go:linkname procpoll libc_poll
|
||||||
//go:linkname procAccess libc_access
|
//go:linkname procAccess libc_access
|
||||||
//go:linkname procAdjtime libc_adjtime
|
//go:linkname procAdjtime libc_adjtime
|
||||||
//go:linkname procChdir libc_chdir
|
//go:linkname procChdir libc_chdir
|
||||||
@@ -278,6 +280,7 @@ var (
|
|||||||
proc__major,
|
proc__major,
|
||||||
proc__minor,
|
proc__minor,
|
||||||
procioctl,
|
procioctl,
|
||||||
|
procpoll,
|
||||||
procAccess,
|
procAccess,
|
||||||
procAdjtime,
|
procAdjtime,
|
||||||
procChdir,
|
procChdir,
|
||||||
@@ -557,6 +560,15 @@ func ioctl(fd int, req uint, arg uintptr) (err error) {
|
|||||||
return
|
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) {
|
func Access(path string, mode uint32) (err error) {
|
||||||
var _p0 *byte
|
var _p0 *byte
|
||||||
_p0, err = BytePtrFromString(path)
|
_p0, err = BytePtrFromString(path)
|
||||||
|
|||||||
@@ -438,3 +438,22 @@ type Winsize struct {
|
|||||||
Xpixel uint16
|
Xpixel uint16
|
||||||
Ypixel 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
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user