]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
rwcancel: use ppoll on Linux for Android
authorJason A. Donenfeld <Jason@zx2c4.com>
Sun, 26 Sep 2021 23:15:58 +0000 (17:15 -0600)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sun, 26 Sep 2021 23:16:38 +0000 (17:16 -0600)
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>
rwcancel/poll_linux.go [new file with mode: 0644]
rwcancel/poll_unix.go [new file with mode: 0644]
rwcancel/rwcancel.go

diff --git a/rwcancel/poll_linux.go b/rwcancel/poll_linux.go
new file mode 100644 (file)
index 0000000..d9938c5
--- /dev/null
@@ -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)
+}
diff --git a/rwcancel/poll_unix.go b/rwcancel/poll_unix.go
new file mode 100644 (file)
index 0000000..37e9686
--- /dev/null
@@ -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)
+}
index 7013b16d8fbb1a83644fd514ddc15c08072fedbd..45cc73b419a5d1a81ee392b65f5ca3257693410c 100644 (file)
@@ -49,7 +49,7 @@ func (rw *RWCancel) ReadyRead() bool {
        pollFds := []unix.PollFd{{Fd: int32(rw.fd), Events: unix.POLLIN}, {Fd: closeFd, Events: unix.POLLIN}}
        var err error
        for {
-               _, err = unix.Poll(pollFds, -1)
+               _, err = poll(pollFds, -1)
                if err == nil || !RetryAfterError(err) {
                        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}}
        var err error
        for {
-               _, err = unix.Poll(pollFds, -1)
+               _, err = poll(pollFds, -1)
                if err == nil || !RetryAfterError(err) {
                        break
                }