use blocking mode pre-go1.11

This commit is contained in:
Song Gao 2019-03-31 15:42:28 -07:00
parent 240a3d7b51
commit 3fe638a7bf
13 changed files with 132 additions and 95 deletions

View file

@ -59,7 +59,10 @@ type sockaddrCtl struct {
var sockaddrCtlSize uintptr = 32
func newTUN(config Config) (ifce *Interface, err error) {
func openDev(config Config) (ifce *Interface, err error) {
if config.DeviceType != TUN {
return nil, errors.New("only tun is implemented on this platform")
}
var fd int
// Supposed to be socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL), but ...
//
@ -111,7 +114,7 @@ func newTUN(config Config) (ifce *Interface, err error) {
return nil, fmt.Errorf("error in syscall.Syscall6(syscall.SYS_GETSOCKOPT, ...): %v", err)
}
if err = syscall.SetNonblock(fd, true); err != nil {
if err = setNonBlock(fd); err != nil {
return nil, fmt.Errorf("setting non-blocking error")
}
@ -124,10 +127,6 @@ func newTUN(config Config) (ifce *Interface, err error) {
}, nil
}
func newTAP(config Config) (ifce *Interface, err error) {
return nil, errors.New("tap interface not implemented on this platform")
}
// tunReadCloser is a hack to work around the first 4 bytes "packet
// information" because there doesn't seem to be an IFF_NO_PI for darwin.
type tunReadCloser struct {