From 8fcd8fee855ac3aceb0bdc1ba0d5313d51fa0a48 Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Mon, 1 Nov 2021 14:01:21 +0800 Subject: [PATCH] Fix(fd): compile error --- core/device/fd/fd.go | 38 -------------------------------- core/device/fd/fd_unix.go | 41 +++++++++++++++++++++++++++++++++++ core/device/fd/fd_windows.go | 11 ++++++++++ core/device/fd/open_others.go | 2 +- 4 files changed, 53 insertions(+), 39 deletions(-) create mode 100644 core/device/fd/fd_unix.go create mode 100644 core/device/fd/fd_windows.go diff --git a/core/device/fd/fd.go b/core/device/fd/fd.go index 631c6715..95e62570 100644 --- a/core/device/fd/fd.go +++ b/core/device/fd/fd.go @@ -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) diff --git a/core/device/fd/fd_unix.go b/core/device/fd/fd_unix.go new file mode 100644 index 00000000..7bce2a96 --- /dev/null +++ b/core/device/fd/fd_unix.go @@ -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) diff --git a/core/device/fd/fd_windows.go b/core/device/fd/fd_windows.go new file mode 100644 index 00000000..29c777c6 --- /dev/null +++ b/core/device/fd/fd_windows.go @@ -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") +} diff --git a/core/device/fd/open_others.go b/core/device/fd/open_others.go index 0bd8e24e..0e014c78 100644 --- a/core/device/fd/open_others.go +++ b/core/device/fd/open_others.go @@ -1,4 +1,4 @@ -//go:build !linux +//go:build !linux && !windows package fd