Xray-core/transport/internet/system_listener_test.go

34 lines
701 B
Go

package internet_test
import (
"context"
"net"
"syscall"
"testing"
"github.com/sagernet/sing/common/control"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/transport/internet"
)
func TestRegisterListenerController(t *testing.T) {
var gotFd uintptr
common.Must(internet.RegisterListenerController(func(network, address string, conn syscall.RawConn) error {
return control.Raw(conn, func(fd uintptr) error {
gotFd = fd
return nil
})
}))
conn, err := internet.ListenSystemPacket(context.Background(), &net.UDPAddr{
IP: net.IPv4zero,
}, nil)
common.Must(err)
common.Must(conn.Close())
if gotFd == 0 {
t.Error("expected none-zero fd, but actually 0")
}
}