Fix and simplify SockOpt in UDP

https://github.com/golang/go/issues/29277
This commit is contained in:
yuhan6665 2024-02-21 13:58:50 -05:00
parent a0f1e1f377
commit 3778a367c8
1 changed files with 4 additions and 6 deletions

View File

@ -2,7 +2,6 @@ package internet
import (
"context"
"runtime"
"syscall"
"time"
@ -67,17 +66,16 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
if err != nil {
return nil, err
}
if runtime.GOOS != "windows" && (sockopt != nil || len(d.controllers) > 0) {
file, err := packetConn.(*net.UDPConn).File()
if sockopt != nil {
sys, err := packetConn.(*net.UDPConn).SyscallConn()
if err != nil {
return nil, err
}
fd := file.Fd()
if sockopt != nil {
sys.Control(func(fd uintptr) {
if err := applyOutboundSocketOptions("udp", dest.NetAddr(), fd, sockopt); err != nil {
newError("failed to apply socket options").Base(err).WriteToLog(session.ExportIDToError(ctx))
}
}
})
}
return &PacketConnWrapper{
Conn: packetConn,