github.com/xmplusdev/xray-core@v1.8.10/transport/internet/sockopt_test.go (about)

     1  package internet_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/google/go-cmp/cmp"
     8  	"github.com/xmplusdev/xray-core/common"
     9  	"github.com/xmplusdev/xray-core/common/buf"
    10  	"github.com/xmplusdev/xray-core/testing/servers/tcp"
    11  	. "github.com/xmplusdev/xray-core/transport/internet"
    12  )
    13  
    14  func TestTCPFastOpen(t *testing.T) {
    15  	tcpServer := tcp.Server{
    16  		MsgProcessor: func(b []byte) []byte {
    17  			return b
    18  		},
    19  	}
    20  	dest, err := tcpServer.StartContext(context.Background(), &SocketConfig{Tfo: 256})
    21  	common.Must(err)
    22  	defer tcpServer.Close()
    23  
    24  	ctx := context.Background()
    25  	dialer := DefaultSystemDialer{}
    26  	conn, err := dialer.Dial(ctx, nil, dest, &SocketConfig{
    27  		Tfo: 1,
    28  	})
    29  	common.Must(err)
    30  	defer conn.Close()
    31  
    32  	_, err = conn.Write([]byte("abcd"))
    33  	common.Must(err)
    34  
    35  	b := buf.New()
    36  	common.Must2(b.ReadFrom(conn))
    37  	if r := cmp.Diff(b.Bytes(), []byte("abcd")); r != "" {
    38  		t.Fatal(r)
    39  	}
    40  }