ListenRangeConfig: default network ( protocol ) to tcp
This commit is contained in:
parent
a2b0babd23
commit
79ae62801f
|
@ -40,7 +40,7 @@ func (l *Listener) Close() error {
|
||||||
// ListenRangeConfig contains options for listening to a free address [Min,Max)
|
// ListenRangeConfig contains options for listening to a free address [Min,Max)
|
||||||
// range. ListenRangeConfig wraps a net.ListenConfig.
|
// range. ListenRangeConfig wraps a net.ListenConfig.
|
||||||
type ListenRangeConfig struct {
|
type ListenRangeConfig struct {
|
||||||
// tcp", "udp"
|
// like "tcp" or "udp". defaults to "tcp".
|
||||||
Network string
|
Network string
|
||||||
Addr string
|
Addr string
|
||||||
Min, Max int
|
Min, Max int
|
||||||
|
@ -51,6 +51,9 @@ type ListenRangeConfig struct {
|
||||||
// until ctx is cancelled.
|
// until ctx is cancelled.
|
||||||
// Listen uses net.ListenConfig.Listen internally.
|
// Listen uses net.ListenConfig.Listen internally.
|
||||||
func (lc ListenRangeConfig) Listen(ctx context.Context) (*Listener, error) {
|
func (lc ListenRangeConfig) Listen(ctx context.Context) (*Listener, error) {
|
||||||
|
if lc.Network == "" {
|
||||||
|
lc.Network = "tcp"
|
||||||
|
}
|
||||||
portRange := lc.Max - lc.Min
|
portRange := lc.Max - lc.Min
|
||||||
for {
|
for {
|
||||||
if err := ctx.Err(); err != nil {
|
if err := ctx.Err(); err != nil {
|
||||||
|
|
Loading…
Reference in New Issue