func (l *TCPListener) run() {
	defer l.listener.Close()
	for {
		select {
		case <-l.stop:
			// stop accepting new connections.
			return
		default:
			conn, err := l.listener.Accept()
			switch {
			case err != nil && isClosedConnError(err):
				return
			case err != nil:
				// an error occurred, restart the listener.
				log.Warnf("Can't listen on port %d, restarting a listener: %v", l.source.Config.Port, err)
				l.listener.Close()
				err := l.startListener()
				if err != nil {
					log.Errorf("Can't restart listener on port %d: %v", l.source.Config.Port, err)
					l.source.Status.Error(err)
					return
				}
				l.source.Status.Success()
				continue
			default:
				l.startTailer(conn)
				l.source.Status.Success()
			}
		}
	}
}
// run accepts new TCP connections and create a dedicated tailer for each.
run accepts new TCP connections and create a dedicated tailer for each.
// run accepts new TCP connections and create a dedicated tailer for each .
func (l *TCPListener) run() {
	defer l.listener.Close()
	for {
		select {
		case <-l.stop:
			return
		default:
			conn, err := l.listener.Accept()
			switch {
			case err != nil && isClosedConnError(err):
				return
			case err != nil:
				log.Warnf("Can't listen on port %d, restarting a listener: %v", l.source.Config.Port, err)
				l.listener.Close()
				err := l.startListener()
				if err != nil {
					log.Errorf("Can't restart listener on port %d: %v", l.source.Config.Port, err)
					l.source.Status.Error(err)
					return
				}
				l.source.Status.Success()
				continue
			default:
				l.startTailer(conn)
				l.source.Status.Success()
			}
		}
	}
}
func ( l * TCPListener ) run ( ) { defer l . listener . Close ( ) for { select { case <- l . stop : return default : conn , err := l . listener . Accept ( ) switch { case err != nil && isClosedConnError ( err ) : return case err != nil : log . Warnf ( " " , l . source . Config . Port , err ) l . listener . Close ( ) err := l . startListener ( ) if err != nil { log . Errorf ( " " , l . source . Config . Port , err ) l . source . Status . Error ( err ) return } l . source . Status . Success ( ) continue default : l . startTailer ( conn ) l . source . Status . Success ( ) } } } }
run accepts new TCP connections and create a dedicated tailer for each.
run accepts new TCP connections and create a dedicated tailer for each .
// stop accepting new connections. // an error occurred, restart the listener.