mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-12-24 13:27:56 +08:00
36 lines
741 B
Go
36 lines
741 B
Go
package netLayer
|
|
|
|
import (
|
|
"net"
|
|
"os"
|
|
)
|
|
|
|
//用于 listen和 dial 配置一些底层参数.
|
|
type Sockopt struct {
|
|
TProxy bool `toml:"tproxy"`
|
|
Somark int `toml:"mark"`
|
|
}
|
|
|
|
//net.TCPListener, net.UnixListener
|
|
type ListenerWithFile interface {
|
|
net.Listener
|
|
File() (f *os.File, err error)
|
|
}
|
|
|
|
//net.UnixConn, net.UDPConn, net.TCPConn, net.IPConn
|
|
type ConnWithFile interface {
|
|
net.Conn
|
|
File() (f *os.File, err error)
|
|
}
|
|
|
|
func SetSockOptForListener(tcplistener ListenerWithFile, sockopt *Sockopt, isudp bool, isipv6 bool) {
|
|
fileDescriptorSource, err := tcplistener.File()
|
|
if err != nil {
|
|
return
|
|
}
|
|
defer fileDescriptorSource.Close()
|
|
SetSockOpt(int(fileDescriptorSource.Fd()), sockopt, isudp, isipv6)
|
|
}
|
|
|
|
//SetSockOpt 是平台相关的.
|