Fix: set non block on TUN device
This commit is contained in:
@@ -15,6 +15,8 @@ type Creator interface {
|
||||
|
||||
var (
|
||||
ErrMknod = errors.New("cannot create TUN device file node")
|
||||
ErrUnixOpen = errors.New("cannot Unix Open TUN device file")
|
||||
ErrSetNonBlock = errors.New("cannot set non block to TUN device file descriptor")
|
||||
)
|
||||
|
||||
// Create creates a TUN device at the path specified.
|
||||
@@ -34,5 +36,16 @@ func (t *Tun) Create(path string) error {
|
||||
return fmt.Errorf("%w: %s", ErrMknod, err)
|
||||
}
|
||||
|
||||
fd, err := unix.Open(path, 0, 0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrUnixOpen, err)
|
||||
}
|
||||
|
||||
const nonBlocking = true
|
||||
err = unix.SetNonblock(fd, nonBlocking)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s", ErrSetNonBlock, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user