Skip to content

Commit

Permalink
Fix(fd): compile error
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu committed Nov 1, 2021
1 parent e06cce1 commit 8fcd8fe
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 39 deletions.
38 changes: 0 additions & 38 deletions core/device/fd/fd.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,3 @@
package fd

import (
"fmt"
"strconv"

"github.com/xjasonlyu/tun2socks/core/device"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/tcpip/stack"
)

const Driver = "fd"

type FD struct {
stack.LinkEndpoint

fd int
mtu uint32
}

func Open(name string, mtu uint32) (device.Device, error) {
fd, err := strconv.Atoi(name)
if err != nil {
return nil, fmt.Errorf("cannot open fd: %s", name)
}
return open(fd, mtu)
}

func (f *FD) Type() string {
return Driver
}

func (f *FD) Name() string {
return strconv.Itoa(f.fd)
}

func (f *FD) Close() error {
return unix.Close(f.fd)
}

var _ device.Device = (*FD)(nil)
41 changes: 41 additions & 0 deletions core/device/fd/fd_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//go:build !windows

package fd

import (
"fmt"
"strconv"

"github.com/xjasonlyu/tun2socks/core/device"
"golang.org/x/sys/unix"
"gvisor.dev/gvisor/pkg/tcpip/stack"
)

type FD struct {
stack.LinkEndpoint

fd int
mtu uint32
}

func Open(name string, mtu uint32) (device.Device, error) {
fd, err := strconv.Atoi(name)
if err != nil {
return nil, fmt.Errorf("cannot open fd: %s", name)
}
return open(fd, mtu)
}

func (f *FD) Type() string {
return Driver
}

func (f *FD) Name() string {
return strconv.Itoa(f.fd)
}

func (f *FD) Close() error {
return unix.Close(f.fd)
}

var _ device.Device = (*FD)(nil)
11 changes: 11 additions & 0 deletions core/device/fd/fd_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package fd

import (
"errors"

"github.com/xjasonlyu/tun2socks/core/device"
)

func Open(name string, mtu uint32) (device.Device, error) {
return nil, errors.New("not supported")
}
2 changes: 1 addition & 1 deletion core/device/fd/open_others.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !linux
//go:build !linux && !windows

package fd

Expand Down

0 comments on commit 8fcd8fe

Please sign in to comment.