瀏覽代碼

Fix SockOpt does not work in UDP

风扇滑翔翼 1 年之前
父節點
當前提交
303beff5dd
共有 1 個文件被更改,包括 12 次插入0 次删除
  1. 12 0
      transport/internet/system_dialer.go

+ 12 - 0
transport/internet/system_dialer.go

@@ -66,6 +66,18 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
 		if err != nil {
 			return nil, err
 		}
+		if sockopt != nil || len(d.controllers) > 0 {
+			file, err := packetConn.(*net.UDPConn).File()
+			if err != nil {
+				return nil, err
+			}
+			fd := file.Fd()
+			if sockopt != nil {
+				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,
 			Dest: destAddr,