mirror of
https://git.zx2c4.com/wireguard-go
synced 2024-11-15 01:05:15 +01:00
rwcancel: use ppoll on Linux for Android
This is a temporary measure while we wait for https://go-review.googlesource.com/c/sys/+/352310 to land. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
217ac1016b
commit
fcc601dbf0
17
rwcancel/poll_linux.go
Normal file
17
rwcancel/poll_linux.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017-2021 WireGuard LLC. All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package rwcancel
|
||||||
|
|
||||||
|
import "golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
func poll(fds []unix.PollFd, timeout int) (n int, err error) {
|
||||||
|
var ts *unix.Timespec
|
||||||
|
if timeout >= 0 {
|
||||||
|
ts = new(unix.Timespec)
|
||||||
|
*ts = unix.NsecToTimespec(int64(timeout) * 1e6)
|
||||||
|
}
|
||||||
|
return unix.Ppoll(fds, ts, nil)
|
||||||
|
}
|
15
rwcancel/poll_unix.go
Normal file
15
rwcancel/poll_unix.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
//go:build !windows && !linux
|
||||||
|
// +build !windows,!linux
|
||||||
|
|
||||||
|
/* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017-2021 WireGuard LLC. All Rights Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package rwcancel
|
||||||
|
|
||||||
|
import "golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
func poll(fds []unix.PollFd, timeout int) (n int, err error) {
|
||||||
|
return unix.Poll(fds, timeout)
|
||||||
|
}
|
@ -49,7 +49,7 @@ func (rw *RWCancel) ReadyRead() bool {
|
|||||||
pollFds := []unix.PollFd{{Fd: int32(rw.fd), Events: unix.POLLIN}, {Fd: closeFd, Events: unix.POLLIN}}
|
pollFds := []unix.PollFd{{Fd: int32(rw.fd), Events: unix.POLLIN}, {Fd: closeFd, Events: unix.POLLIN}}
|
||||||
var err error
|
var err error
|
||||||
for {
|
for {
|
||||||
_, err = unix.Poll(pollFds, -1)
|
_, err = poll(pollFds, -1)
|
||||||
if err == nil || !RetryAfterError(err) {
|
if err == nil || !RetryAfterError(err) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ func (rw *RWCancel) ReadyWrite() bool {
|
|||||||
pollFds := []unix.PollFd{{Fd: int32(rw.fd), Events: unix.POLLOUT}, {Fd: closeFd, Events: unix.POLLOUT}}
|
pollFds := []unix.PollFd{{Fd: int32(rw.fd), Events: unix.POLLOUT}, {Fd: closeFd, Events: unix.POLLOUT}}
|
||||||
var err error
|
var err error
|
||||||
for {
|
for {
|
||||||
_, err = unix.Poll(pollFds, -1)
|
_, err = poll(pollFds, -1)
|
||||||
if err == nil || !RetryAfterError(err) {
|
if err == nil || !RetryAfterError(err) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user