Skip to content

Commit

Permalink
Fix and simplify SockOpt in UDP
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhan6665 committed Feb 21, 2024
1 parent a0f1e1f commit 3778a36
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions transport/internet/system_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package internet

import (
"context"
"runtime"
"syscall"
"time"

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3778a36

Please sign in to comment.