|
|
|
@ -15,10 +15,10 @@ var (
|
|
|
|
|
type controller func(network, address string, fd uintptr) error |
|
|
|
|
|
|
|
|
|
type DefaultListener struct { |
|
|
|
|
contollers []controller |
|
|
|
|
controllers []controller |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getControlFunc(ctx context.Context, sockopt *SocketConfig, contollers []controller) func(network, address string, c syscall.RawConn) error { |
|
|
|
|
func getControlFunc(ctx context.Context, sockopt *SocketConfig, controllers []controller) func(network, address string, c syscall.RawConn) error { |
|
|
|
|
return func(network, address string, c syscall.RawConn) error { |
|
|
|
|
return c.Control(func(fd uintptr) { |
|
|
|
|
if sockopt != nil { |
|
|
|
@ -27,7 +27,7 @@ func getControlFunc(ctx context.Context, sockopt *SocketConfig, contollers []con
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, controller := range contollers { |
|
|
|
|
for _, controller := range controllers { |
|
|
|
|
if err := controller(network, address, fd); err != nil { |
|
|
|
|
newError("failed to apply external controller").Base(err).WriteToLog(session.ExportIDToError(ctx)) |
|
|
|
|
} |
|
|
|
@ -39,8 +39,8 @@ func getControlFunc(ctx context.Context, sockopt *SocketConfig, contollers []con
|
|
|
|
|
func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *SocketConfig) (net.Listener, error) { |
|
|
|
|
var lc net.ListenConfig |
|
|
|
|
|
|
|
|
|
if sockopt != nil || len(dl.contollers) > 0 { |
|
|
|
|
lc.Control = getControlFunc(ctx, sockopt, dl.contollers) |
|
|
|
|
if sockopt != nil || len(dl.controllers) > 0 { |
|
|
|
|
lc.Control = getControlFunc(ctx, sockopt, dl.controllers) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return lc.Listen(ctx, addr.Network(), addr.String()) |
|
|
|
@ -49,8 +49,8 @@ func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *S
|
|
|
|
|
func (dl *DefaultListener) ListenPacket(ctx context.Context, addr net.Addr, sockopt *SocketConfig) (net.PacketConn, error) { |
|
|
|
|
var lc net.ListenConfig |
|
|
|
|
|
|
|
|
|
if sockopt != nil || len(dl.contollers) > 0 { |
|
|
|
|
lc.Control = getControlFunc(ctx, sockopt, dl.contollers) |
|
|
|
|
if sockopt != nil || len(dl.controllers) > 0 { |
|
|
|
|
lc.Control = getControlFunc(ctx, sockopt, dl.controllers) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return lc.ListenPacket(ctx, addr.Network(), addr.String()) |
|
|
|
@ -65,6 +65,6 @@ func RegisterListenerController(controller func(network, address string, fd uint
|
|
|
|
|
return newError("nil listener controller") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
effectiveListener.contollers = append(effectiveListener.contollers, controller) |
|
|
|
|
effectiveListener.controllers = append(effectiveListener.controllers, controller) |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|