Browse Source

test tfo on listener

Darien Raymond 7 years ago
parent
commit
b9e4a4882c
2 changed files with 12 additions and 3 deletions
  1. 7 2
      testing/servers/tcp/tcp.go
  2. 5 1
      transport/internet/sockopt_test.go

+ 7 - 2
testing/servers/tcp/tcp.go

@@ -1,12 +1,14 @@
 package tcp
 
 import (
+	"context"
 	"fmt"
 	"io"
 
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/task"
+	"v2ray.com/core/transport/internet"
 	"v2ray.com/core/transport/pipe"
 )
 
@@ -20,14 +22,17 @@ type Server struct {
 }
 
 func (server *Server) Start() (net.Destination, error) {
+	return server.StartContext(context.Background())
+}
+
+func (server *Server) StartContext(ctx context.Context) (net.Destination, error) {
 	listenerAddr := server.Listen
 	if listenerAddr == nil {
 		listenerAddr = net.LocalHostIP
 	}
-	listener, err := net.ListenTCP("tcp", &net.TCPAddr{
+	listener, err := internet.ListenSystemTCP(ctx, &net.TCPAddr{
 		IP:   listenerAddr.IP(),
 		Port: int(server.Port),
-		Zone: "",
 	})
 	if err != nil {
 		return net.Destination{}, err

+ 5 - 1
transport/internet/sockopt_test.go

@@ -17,7 +17,11 @@ func TestTCPFastOpen(t *testing.T) {
 			return b
 		},
 	}
-	dest, err := tcpServer.Start()
+	dest, err := tcpServer.StartContext(ContextWithStreamSettings(context.Background(), &MemoryStreamConfig{
+		SocketSettings: &SocketConfig{
+			Tfo: SocketConfig_Enable,
+		},
+	}))
 	common.Must(err)
 	defer tcpServer.Close()