fix(sockopts): error handling in applyToUDPConn

it is just no reason to use named err retval here
This commit is contained in:
Haruue 2024-04-05 13:20:17 +08:00
parent 5bebfd5732
commit e6da1f348c
No known key found for this signature in database
GPG key ID: F6083B28CBCBC148

View file

@ -53,27 +53,24 @@ func (o *SocketOptions) ListenUDP() (uconn net.PacketConn, err error) {
return return
} }
func (o *SocketOptions) applyToUDPConn(c *net.UDPConn) (err error) { func (o *SocketOptions) applyToUDPConn(c *net.UDPConn) error {
if o.BindInterface != nil && bindInterfaceFunc != nil { if o.BindInterface != nil && bindInterfaceFunc != nil {
err = bindInterfaceFunc(c, *o.BindInterface) err := bindInterfaceFunc(c, *o.BindInterface)
if err != nil { if err != nil {
err = fmt.Errorf("failed to bind to interface: %w", err) return fmt.Errorf("failed to bind to interface: %w", err)
return
} }
} }
if o.FirewallMark != nil && firewallMarkFunc != nil { if o.FirewallMark != nil && firewallMarkFunc != nil {
err = firewallMarkFunc(c, *o.FirewallMark) err := firewallMarkFunc(c, *o.FirewallMark)
if err != nil { if err != nil {
err = fmt.Errorf("failed to set fwmark: %w", err) return fmt.Errorf("failed to set fwmark: %w", err)
return
} }
} }
if o.FdControlUnixSocket != nil && fdControlUnixSocketFunc != nil { if o.FdControlUnixSocket != nil && fdControlUnixSocketFunc != nil {
err = fdControlUnixSocketFunc(c, *o.FdControlUnixSocket) err := fdControlUnixSocketFunc(c, *o.FdControlUnixSocket)
if err != nil { if err != nil {
err = fmt.Errorf("failed to send fd to control unix socket: %w", err) return fmt.Errorf("failed to send fd to control unix socket: %w", err)
return
} }
} }
return return nil
} }