Skip to content

Commit 8fcd8fe

Browse files
committed
Fix(fd): compile error
1 parent e06cce1 commit 8fcd8fe

File tree

4 files changed

+53
-39
lines changed

4 files changed

+53
-39
lines changed

core/device/fd/fd.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,3 @@
11
package fd
22

3-
import (
4-
"fmt"
5-
"strconv"
6-
7-
"github.com/xjasonlyu/tun2socks/core/device"
8-
"golang.org/x/sys/unix"
9-
"gvisor.dev/gvisor/pkg/tcpip/stack"
10-
)
11-
123
const Driver = "fd"
13-
14-
type FD struct {
15-
stack.LinkEndpoint
16-
17-
fd int
18-
mtu uint32
19-
}
20-
21-
func Open(name string, mtu uint32) (device.Device, error) {
22-
fd, err := strconv.Atoi(name)
23-
if err != nil {
24-
return nil, fmt.Errorf("cannot open fd: %s", name)
25-
}
26-
return open(fd, mtu)
27-
}
28-
29-
func (f *FD) Type() string {
30-
return Driver
31-
}
32-
33-
func (f *FD) Name() string {
34-
return strconv.Itoa(f.fd)
35-
}
36-
37-
func (f *FD) Close() error {
38-
return unix.Close(f.fd)
39-
}
40-
41-
var _ device.Device = (*FD)(nil)

core/device/fd/fd_unix.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//go:build !windows
2+
3+
package fd
4+
5+
import (
6+
"fmt"
7+
"strconv"
8+
9+
"github.com/xjasonlyu/tun2socks/core/device"
10+
"golang.org/x/sys/unix"
11+
"gvisor.dev/gvisor/pkg/tcpip/stack"
12+
)
13+
14+
type FD struct {
15+
stack.LinkEndpoint
16+
17+
fd int
18+
mtu uint32
19+
}
20+
21+
func Open(name string, mtu uint32) (device.Device, error) {
22+
fd, err := strconv.Atoi(name)
23+
if err != nil {
24+
return nil, fmt.Errorf("cannot open fd: %s", name)
25+
}
26+
return open(fd, mtu)
27+
}
28+
29+
func (f *FD) Type() string {
30+
return Driver
31+
}
32+
33+
func (f *FD) Name() string {
34+
return strconv.Itoa(f.fd)
35+
}
36+
37+
func (f *FD) Close() error {
38+
return unix.Close(f.fd)
39+
}
40+
41+
var _ device.Device = (*FD)(nil)

core/device/fd/fd_windows.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package fd
2+
3+
import (
4+
"errors"
5+
6+
"github.com/xjasonlyu/tun2socks/core/device"
7+
)
8+
9+
func Open(name string, mtu uint32) (device.Device, error) {
10+
return nil, errors.New("not supported")
11+
}

core/device/fd/open_others.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build !linux
1+
//go:build !linux && !windows
22

33
package fd
44

0 commit comments

Comments
 (0)