Add ApplySockopt

This commit is contained in:
世界 2021-09-29 18:52:59 +08:00
parent a4f657f787
commit 073ba6f1c5
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4

View File

@ -104,6 +104,17 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
return dialer.DialContext(ctx, dest.Network.SystemString(), dest.NetAddr()) return dialer.DialContext(ctx, dest.Network.SystemString(), dest.NetAddr())
} }
func ApplySockopt(sockopt *SocketConfig, dest net.Destination, fd uintptr, ctx context.Context) {
if err := applyOutboundSocketOptions(dest.Network.String(), dest.Address.String(), fd, sockopt); err != nil {
newError("failed to apply socket options").Base(err).WriteToLog(session.ExportIDToError(ctx))
}
if dest.Network == net.Network_UDP && hasBindAddr(sockopt) {
if err := bindAddr(fd, sockopt.BindAddress, sockopt.BindPort); err != nil {
newError("failed to bind source address to ", sockopt.BindAddress).Base(err).WriteToLog(session.ExportIDToError(ctx))
}
}
}
type PacketConnWrapper struct { type PacketConnWrapper struct {
Conn net.PacketConn Conn net.PacketConn
Dest net.Addr Dest net.Addr