ListenRangeConfig: default network ( protocol ) to tcp

This commit is contained in:
Adrien Delorme 2019-04-30 14:55:38 +02:00
parent a2b0babd23
commit 79ae62801f
1 changed files with 4 additions and 1 deletions

View File

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