Skip to content

Commit be12694

Browse files
committed
Fix compatibility
1 parent 9b2df36 commit be12694

File tree

12 files changed

+51
-11
lines changed

12 files changed

+51
-11
lines changed

errors_go120.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build !go1.21
2+
3+
package tfo
4+
5+
import "errors"
6+
7+
var ErrUnsupported = errors.New("unsupported operation")

errors_go121.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build go1.21
2+
3+
package tfo
4+
5+
import "errors"
6+
7+
var ErrUnsupported = errors.ErrUnsupported

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/metacubex/tfo-go
22

3-
go 1.22.0
3+
go 1.20.0
44

55
require golang.org/x/sys v0.17.0

mptcp_go120.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//go:build !go1.21
2+
3+
package tfo
4+
5+
import "net"
6+
7+
func multipathTCP(d net.Dialer) bool {
8+
return false
9+
}
10+
11+
func setMultipathTCP(d net.Dialer, use bool) {
12+
return
13+
}

mptcp_go121.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//go:build go1.21
2+
3+
package tfo
4+
5+
import "net"
6+
7+
func multipathTCP(d net.Dialer) bool {
8+
return d.MultipathTCP()
9+
}
10+
11+
func setMultipathTCP(d net.Dialer, use bool) {
12+
d.SetMultipathTCP(use)
13+
}

tfo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (PlatformUnsupportedError) Error() string {
3232
}
3333

3434
func (PlatformUnsupportedError) Is(target error) bool {
35-
return target == errors.ErrUnsupported
35+
return target == ErrUnsupported
3636
}
3737

3838
var runtimeListenNoTFO atomic.Bool

tfo_bsd+linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (d *Dialer) dialSingle(ctx context.Context, network string, laddr, raddr *n
6464
}
6565

6666
if err = setTFODialerFromSocket(uintptr(fd)); err != nil {
67-
if !d.Fallback || !errors.Is(err, errors.ErrUnsupported) {
67+
if !d.Fallback || !errors.Is(err, ErrUnsupported) {
6868
unix.Close(fd)
6969
return nil, wrapSyscallError("setsockopt("+setTFODialerFromSocketSockoptName+")", err)
7070
}

tfo_bsd+windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (d *Dialer) dialTFO(ctx context.Context, network, address string, b []byte)
1616

1717
func dialTCPAddr(network string, laddr, raddr *net.TCPAddr, b []byte) (*net.TCPConn, error) {
1818
var d Dialer
19-
d.SetMultipathTCP(false) // Align with [net.DialTCP].
19+
setMultipathTCP(d.Dialer, false) // Align with [net.DialTCP].
2020
c, err := d.dialSingle(context.Background(), network, laddr, raddr, b, nil)
2121
if err != nil {
2222
return nil, &net.OpError{Op: "dial", Net: network, Source: laddr, Addr: raddr, Err: err}

tfo_darwin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (lc *ListenConfig) listenTFO(ctx context.Context, network, address string)
3232
}
3333

3434
if err != nil {
35-
if !lc.Fallback || !errors.Is(err, errors.ErrUnsupported) {
35+
if !lc.Fallback || !errors.Is(err, ErrUnsupported) {
3636
return wrapSyscallError("setsockopt(TCP_FASTOPEN_FORCE_ENABLE)", err)
3737
}
3838
runtimeListenNoTFO.Store(true)
@@ -60,7 +60,7 @@ func (lc *ListenConfig) listenTFO(ctx context.Context, network, address string)
6060

6161
if err != nil {
6262
ln.Close()
63-
if !lc.Fallback || !errors.Is(err, errors.ErrUnsupported) {
63+
if !lc.Fallback || !errors.Is(err, ErrUnsupported) {
6464
return nil, wrapSyscallError("setsockopt(TCP_FASTOPEN)", err)
6565
}
6666
runtimeListenNoTFO.Store(true)
@@ -72,7 +72,7 @@ func (lc *ListenConfig) listenTFO(ctx context.Context, network, address string)
7272
const AF_MULTIPATH = 39
7373

7474
func (d *Dialer) socket(domain int) (fd int, err error) {
75-
if d.MultipathTCP() {
75+
if multipathTCP(d.Dialer) {
7676
domain = AF_MULTIPATH
7777
}
7878
fd, err = unix.Socket(domain, unix.SOCK_STREAM, unix.IPPROTO_TCP)
@@ -89,7 +89,7 @@ func (d *Dialer) socket(domain int) (fd int, err error) {
8989
}
9090

9191
func (d *Dialer) setIPv6Only(fd int, family int, ipv6only bool) error {
92-
if d.MultipathTCP() {
92+
if multipathTCP(d.Dialer) {
9393
return nil
9494
}
9595
return setIPv6Only(fd, family, ipv6only)

tfo_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (d *Dialer) dialTFO(ctx context.Context, network, address string, b []byte)
6363
}
6464

6565
if err != nil {
66-
if d.Fallback && errors.Is(err, errors.ErrUnsupported) {
66+
if d.Fallback && errors.Is(err, ErrUnsupported) {
6767
canFallback = true
6868
}
6969
return wrapSyscallError("setsockopt(TCP_FASTOPEN_CONNECT)", err)

0 commit comments

Comments
 (0)