mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-05 04:29:19 +02:00
Fix and simplify SockOpt in UDP
https://github.com/golang/go/issues/29277
This commit is contained in:
parent
a0f1e1f377
commit
3778a367c8
|
@ -2,7 +2,6 @@ package internet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"runtime"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -67,17 +66,16 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if runtime.GOOS != "windows" && (sockopt != nil || len(d.controllers) > 0) {
|
if sockopt != nil {
|
||||||
file, err := packetConn.(*net.UDPConn).File()
|
sys, err := packetConn.(*net.UDPConn).SyscallConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
fd := file.Fd()
|
sys.Control(func(fd uintptr) {
|
||||||
if sockopt != nil {
|
|
||||||
if err := applyOutboundSocketOptions("udp", dest.NetAddr(), fd, sockopt); err != nil {
|
if err := applyOutboundSocketOptions("udp", dest.NetAddr(), fd, sockopt); err != nil {
|
||||||
newError("failed to apply socket options").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
newError("failed to apply socket options").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
return &PacketConnWrapper{
|
return &PacketConnWrapper{
|
||||||
Conn: packetConn,
|
Conn: packetConn,
|
||||||
|
|
Loading…
Reference in New Issue