2021-09-06 23:07:34 +08:00
|
|
|
package dialer
|
|
|
|
|
2021-11-07 16:48:51 +08:00
|
|
|
import "go.uber.org/atomic"
|
2021-09-06 23:07:34 +08:00
|
|
|
|
2021-11-07 16:48:51 +08:00
|
|
|
var (
|
2022-02-17 14:23:47 +08:00
|
|
|
DefaultOptions []Option
|
|
|
|
DefaultInterface = atomic.NewString("")
|
|
|
|
DefaultRoutingMark = atomic.NewInt32(0)
|
2022-04-23 00:27:22 +08:00
|
|
|
TCPConcurrent = false
|
2021-11-07 16:48:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type option struct {
|
2021-09-06 23:07:34 +08:00
|
|
|
interfaceName string
|
|
|
|
addrReuse bool
|
2021-11-08 16:59:48 +08:00
|
|
|
routingMark int
|
2022-03-28 00:44:13 +08:00
|
|
|
direct bool
|
2021-09-06 23:07:34 +08:00
|
|
|
}
|
|
|
|
|
2021-11-07 16:48:51 +08:00
|
|
|
type Option func(opt *option)
|
2021-09-06 23:07:34 +08:00
|
|
|
|
|
|
|
func WithInterface(name string) Option {
|
2021-11-07 16:48:51 +08:00
|
|
|
return func(opt *option) {
|
2021-09-06 23:07:34 +08:00
|
|
|
opt.interfaceName = name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithAddrReuse(reuse bool) Option {
|
2021-11-07 16:48:51 +08:00
|
|
|
return func(opt *option) {
|
2021-09-06 23:07:34 +08:00
|
|
|
opt.addrReuse = reuse
|
|
|
|
}
|
|
|
|
}
|
2021-11-08 16:59:48 +08:00
|
|
|
|
|
|
|
func WithRoutingMark(mark int) Option {
|
|
|
|
return func(opt *option) {
|
|
|
|
opt.routingMark = mark
|
|
|
|
}
|
|
|
|
}
|
2022-03-28 00:44:13 +08:00
|
|
|
|
|
|
|
func WithDirect() Option {
|
|
|
|
return func(opt *option) {
|
|
|
|
opt.direct = true
|
|
|
|
}
|
|
|
|
}
|