// WithListener is an option for JSONSource which causes it to use the given
// listener. It will infer the address from the listener.
494447
func WithListener(l net.Listener) JSONSourceOption {
	return func(j *JSONSource) {
		j.listener = l
		j.addr = l.Addr().String()
	}
}
838947
func (r RandomPortListenerSource) GetListener() (net.Listener, string, error) {
	localhost := "127.0.0.1"
	listener, err := net.Listen("tcp", fmt.Sprintf("%s:0", localhost))
	if err != nil {
		return nil, "", err
	}
	port := listener.Addr().(*net.TCPAddr).Port
	address := fmt.Sprintf("%s:%d", localhost, port)
	return listener, address, nil
}
189142
func (d *eventDispatcher) AddEventListener(typ string, listener EventListener) {
	d.Lock()
	defer d.Unlock()
	d.listeners[typ] = append(d.listeners[typ], listener)
}
460860
func NewListenersOn(list []ListenTarget) ([]net.Listener, error) {
	ret := []net.Listener{}
	for _, t := range list {
		l, err := NewListenerOn(t)
		if err != nil {
			return nil, err
		}
		ret = append(ret, l)
	}
	return ret, nil
}
950552
func (h *HTTPServer) Listener() net.Listener {
	h.lock.RLock()
	listener := h.listener
	h.lock.RUnlock()
	return listener
}
378423
func (s *SiteConfig) AddListenerMiddleware(l ListenerMiddleware) {
	s.listenerMiddleware = append(s.listenerMiddleware, l)
}
856168
func (sd *etcdServiceDiscovery) AddListener(listener SDListener) {
	sd.listeners = append(sd.listeners, listener)
}
183208
func (p *PortRangeListenerSource) GetListener() (listener net.Listener, address string, err error) {
	p.Lock()
	defer p.Unlock()
	localhost := "127.0.0.1"
	if p.pinnedPort > 0 {
		address = fmt.Sprintf("%s:%d", localhost, p.pinnedPort)
		if listener, err = net.Listen("tcp", address); err != nil {
			return listener, address, ErrPinnedPortInUse
		}
		return listener, address, nil
	}
	for port := p.low; port <= p.high; port++ {
		address = fmt.Sprintf("%s:%d", localhost, port)
		listener, err = net.Listen("tcp", address)
		if err == nil {
			p.pinnedPort = port
			return listener, address, nil
		}
	}
	return listener, address, errors.New("failed to bind to port in range")
}
140847
func Listener(l net.Listener) net.Listener {
	return keepaliveListener{l.(*net.TCPListener)}
}
793571
func (cfg *Config) NewListener(network, addr string) (net.Listener, error) {
	sa, soType, err := getSockaddr(network, addr)
	if err != nil {
		return nil, err
	}

	fd, err := newSocketCloexec(soType, syscall.SOCK_STREAM, syscall.IPPROTO_TCP)
	if err != nil {
		return nil, err
	}

	if err = cfg.fdSetup(fd, sa, addr); err != nil {
		syscall.Close(fd)
		return nil, err
	}

	name := fmt.Sprintf("reuseport.%d.%s.%s", os.Getpid(), network, addr)
	file := os.NewFile(uintptr(fd), name)
	ln, err := net.FileListener(file)
	if err != nil {
		file.Close()
		return nil, err
	}

	if err = file.Close(); err != nil {
		ln.Close()
		return nil, err
	}

	return ln, nil
}
107761
func (s *CreateListenerOutput) SetListener(v *Listener) *CreateListenerOutput {
	s.Listener = v
	return s
}
315082
func (pf *PortForwarder) getListener(protocol string, hostname string, port *ForwardedPort) (net.Listener, error) {
	listener, err := net.Listen(protocol, fmt.Sprintf("%s:%d", hostname, port.Local))
	if err != nil {
		util.HandleError(fmt.Errorf("Unable to create listener: Error %s", err))
		return nil, err
	}
	listenerAddress := listener.Addr().String()
	host, localPort, _ := net.SplitHostPort(listenerAddress)
	localPortUInt, err := strconv.ParseUint(localPort, 10, 16)

	if err != nil {
		return nil, fmt.Errorf("Error parsing local port: %s from %s (%s)", err, listenerAddress, host)
	}
	port.Local = uint16(localPortUInt)
	glog.Infof("Forwarding from %s:%d -> %d", hostname, localPortUInt, port.Remote)

	return listener, nil
}
869687
func (entry *Entry) WithField(key string, value interface{}) *Entry {
	return entry.WithFields(Fields{key: value})
}
739940
func (s *Server) AddListener(listener func(config.Configuration)) {
	if s.configurationListeners == nil {
		s.configurationListeners = make([]func(config.Configuration), 0)
	}
	s.configurationListeners = append(s.configurationListeners, listener)
}
459907
func (o *GetNodesIdentifierCatalogsSourceParams) WithSource(source string) *GetNodesIdentifierCatalogsSourceParams {
	o.Source = source
	return o
}
854127
func (e *Entry) WithField(key string, value interface{}) *Entry {
	return e.WithFields(Fields{key: value})
}
487581
func (s *DescribeListenerOutput) SetListener(v *Listener) *DescribeListenerOutput {
	s.Listener = v
	return s
}