aboutsummaryrefslogtreecommitdiffstats
path: root/tun
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-24 15:29:16 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-24 15:36:29 +0200
commit2f2eca894744baef365aaa07554f56979159d988 (patch)
tree56ecc658ff124222643a13ed9bd75c3a703e726b /tun
parentRemove old makefile artifact (diff)
downloadwireguard-go-2f2eca894744baef365aaa07554f56979159d988.tar.xz
wireguard-go-2f2eca894744baef365aaa07554f56979159d988.zip
Catch EINTR
Diffstat (limited to 'tun')
-rw-r--r--tun/tun_darwin.go9
-rw-r--r--tun/tun_freebsd.go9
-rw-r--r--tun/tun_linux.go6
-rw-r--r--tun/tun_openbsd.go12
4 files changed, 24 insertions, 12 deletions
diff --git a/tun/tun_darwin.go b/tun/tun_darwin.go
index 04020cb..f692bbe 100644
--- a/tun/tun_darwin.go
+++ b/tun/tun_darwin.go
@@ -7,14 +7,15 @@
package tun
import (
- "git.zx2c4.com/wireguard-go/rwcancel"
"errors"
"fmt"
+ "git.zx2c4.com/wireguard-go/rwcancel"
"golang.org/x/net/ipv6"
"golang.org/x/sys/unix"
"io/ioutil"
"net"
"os"
+ "syscall"
"unsafe"
)
@@ -54,8 +55,12 @@ func (tun *nativeTun) routineRouteListener(tunIfindex int) {
data := make([]byte, os.Getpagesize())
for {
+ retry:
n, err := unix.Read(tun.routeSocket, data)
if err != nil {
+ if errno, ok := err.(syscall.Errno); ok && errno == syscall.EINTR {
+ goto retry
+ }
tun.errors <- err
return
}
@@ -259,7 +264,7 @@ func (tun *nativeTun) doRead(buff []byte, offset int) (int, error) {
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
for {
n, err := tun.doRead(buff, offset)
- if err == nil || !rwcancel.ErrorIsEAGAIN(err) {
+ if err == nil || !rwcancel.RetryAfterError(err) {
return n, err
}
if !tun.rwcancel.ReadyRead() {
diff --git a/tun/tun_freebsd.go b/tun/tun_freebsd.go
index bd70104..435ff91 100644
--- a/tun/tun_freebsd.go
+++ b/tun/tun_freebsd.go
@@ -6,14 +6,15 @@
package tun
import (
- "git.zx2c4.com/wireguard-go/rwcancel"
"bytes"
"errors"
"fmt"
+ "git.zx2c4.com/wireguard-go/rwcancel"
"golang.org/x/net/ipv6"
"golang.org/x/sys/unix"
"net"
"os"
+ "syscall"
"unsafe"
)
@@ -67,8 +68,12 @@ func (tun *nativeTun) routineRouteListener(tunIfindex int) {
data := make([]byte, os.Getpagesize())
for {
+ retry:
n, err := unix.Read(tun.routeSocket, data)
if err != nil {
+ if errno, ok := err.(syscall.Errno); ok && errno == syscall.EINTR {
+ goto retry
+ }
tun.errors <- err
return
}
@@ -392,7 +397,7 @@ func (tun *nativeTun) doRead(buff []byte, offset int) (int, error) {
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
for {
n, err := tun.doRead(buff, offset)
- if err == nil || !rwcancel.ErrorIsEAGAIN(err) {
+ if err == nil || !rwcancel.RetryAfterError(err) {
return n, err
}
if !tun.rwcancel.ReadyRead() {
diff --git a/tun/tun_linux.go b/tun/tun_linux.go
index d048c21..2119696 100644
--- a/tun/tun_linux.go
+++ b/tun/tun_linux.go
@@ -12,10 +12,10 @@ package tun
*/
import (
- "git.zx2c4.com/wireguard-go/rwcancel"
"bytes"
"errors"
"fmt"
+ "git.zx2c4.com/wireguard-go/rwcancel"
"golang.org/x/net/ipv6"
"golang.org/x/sys/unix"
"net"
@@ -102,7 +102,7 @@ func (tun *nativeTun) routineNetlinkListener() {
var msgn int
for {
msgn, _, _, _, err = unix.Recvmsg(tun.netlinkSock, msg[:], nil, 0)
- if err == nil || !rwcancel.ErrorIsEAGAIN(err) {
+ if err == nil || !rwcancel.RetryAfterError(err) {
break
}
if !tun.netlinkCancel.ReadyRead() {
@@ -334,7 +334,7 @@ func (tun *nativeTun) doRead(buff []byte, offset int) (int, error) {
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
for {
n, err := tun.doRead(buff, offset)
- if err == nil || !rwcancel.ErrorIsEAGAIN(err) {
+ if err == nil || !rwcancel.RetryAfterError(err) {
return n, err
}
if !tun.fdCancel.ReadyRead() {
diff --git a/tun/tun_openbsd.go b/tun/tun_openbsd.go
index 709b5cd..3c1878b 100644
--- a/tun/tun_openbsd.go
+++ b/tun/tun_openbsd.go
@@ -6,9 +6,9 @@
package tun
import (
- "git.zx2c4.com/wireguard-go/rwcancel"
"errors"
"fmt"
+ "git.zx2c4.com/wireguard-go/rwcancel"
"golang.org/x/net/ipv6"
"golang.org/x/sys/unix"
"io/ioutil"
@@ -46,8 +46,12 @@ func (tun *nativeTun) routineRouteListener(tunIfindex int) {
data := make([]byte, os.Getpagesize())
for {
+ retry:
n, err := unix.Read(tun.routeSocket, data)
if err != nil {
+ if errno, ok := err.(syscall.Errno); ok && errno == syscall.EINTR {
+ goto retry
+ }
tun.errors <- err
return
}
@@ -90,9 +94,7 @@ func (tun *nativeTun) routineRouteListener(tunIfindex int) {
func errorIsEBUSY(err error) bool {
if pe, ok := err.(*os.PathError); ok {
- if errno, ok := pe.Err.(syscall.Errno); ok && errno == syscall.EBUSY {
- return true
- }
+ err = pe.Err
}
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EBUSY {
return true
@@ -237,7 +239,7 @@ func (tun *nativeTun) doRead(buff []byte, offset int) (int, error) {
func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
for {
n, err := tun.doRead(buff, offset)
- if err == nil || !rwcancel.ErrorIsEAGAIN(err) {
+ if err == nil || !rwcancel.RetryAfterError(err) {
return n, err
}
if !tun.rwcancel.ReadyRead() {