func (s *session) pollAndSync() {
	log.Debugf("[session.registry] start pollAndSync()\b")
	defer log.Debugf("[session.registry] end pollAndSync()\n")

	sessionServer := s.registry.srv.sessionServer
	if sessionServer == nil {
		return
	}
	errCount := 0
	sync := func() error {
		sess, err := sessionServer.GetSession(s.id)
		if sess == nil {
			return trace.Wrap(err)
		}
		var active = true
		sessionServer.UpdateSession(rsession.UpdateRequest{
			ID:      sess.ID,
			Active:  &active,
			Parties: nil,
		})
		winSize, err := s.term.getWinsize()
		if err != nil {
			return err
		}
		termSizeChanged := (int(winSize.Width) != sess.TerminalParams.W ||
			int(winSize.Height) != sess.TerminalParams.H)
		if termSizeChanged {
			log.Debugf("terminal has changed from: %v to %v", sess.TerminalParams, winSize)
			err = s.term.setWinsize(sess.TerminalParams)
		}
		return err
	}

	tick := time.NewTicker(defaults.TerminalSizeRefreshPeriod)
	defer tick.Stop()
	for {
		if err := sync(); err != nil {
			log.Infof("sync term error: %v", err)
			errCount++
			// if the error count keeps going up, this means we're stuck in
			// a bad state: end this goroutine to avoid leaks
			if errCount > maxTermSyncErrorCount {
				return
			}
		} else {
			errCount = 0
		}
		select {
		case <-s.closeC:
			log.Infof("[SSH] terminal sync stopped")
			return
		case <-tick.C:
		}
	}
}
// pollAndSync is a loop inside a goroutite which keeps synchronizing the terminal
// size to what's in the session (so all connected parties have the same terminal size)
// it also updates 'active' field on the session.
pollAndSync is a loop inside a goroutite which keeps synchronizing the terminal
size to what's in the session (so all connected parties have the same terminal size)
it also updates 'active' field on the session.
// pollAndSync is a loop inside a goroutite which keeps synchronizing the terminal // size to what ' s in the session ( so all connected parties have the same terminal size ) // it also updates ' active ' field on the session .
func (s *session) pollAndSync() {
	log.Debugf("[session.registry] start pollAndSync()\b")
	defer log.Debugf("[session.registry] end pollAndSync()\n")
	sessionServer := s.registry.srv.sessionServer
	if sessionServer == nil {
		return
	}
	errCount := 0
	sync := func() error {
		sess, err := sessionServer.GetSession(s.id)
		if sess == nil {
			return trace.Wrap(err)
		}
		var active = true
		sessionServer.UpdateSession(rsession.UpdateRequest{
			ID:      sess.ID,
			Active:  &active,
			Parties: nil,
		})
		winSize, err := s.term.getWinsize()
		if err != nil {
			return err
		}
		termSizeChanged := (int(winSize.Width) != sess.TerminalParams.W ||
			int(winSize.Height) != sess.TerminalParams.H)
		if termSizeChanged {
			log.Debugf("terminal has changed from: %v to %v", sess.TerminalParams, winSize)
			err = s.term.setWinsize(sess.TerminalParams)
		}
		return err
	}
	tick := time.NewTicker(defaults.TerminalSizeRefreshPeriod)
	defer tick.Stop()
	for {
		if err := sync(); err != nil {
			log.Infof("sync term error: %v", err)
			errCount++
			if errCount > maxTermSyncErrorCount {
				return
			}
		} else {
			errCount = 0
		}
		select {
		case <-s.closeC:
			log.Infof("[SSH] terminal sync stopped")
			return
		case <-tick.C:
		}
	}
}
func ( s * session ) pollAndSync ( ) { log . Debugf ( " \b " ) defer log . Debugf ( " \n " ) sessionServer := s . registry . srv . sessionServer if sessionServer == nil { return } errCount := 0 sync := func ( ) error { sess , err := sessionServer . GetSession ( s . id ) if sess == nil { return trace . Wrap ( err ) } var active = true sessionServer . UpdateSession ( rsession . UpdateRequest { ID : sess . ID , Active : & active , Parties : nil , } ) winSize , err := s . term . getWinsize ( ) if err != nil { return err } termSizeChanged := ( int ( winSize . Width ) != sess . TerminalParams . W || int ( winSize . Height ) != sess . TerminalParams . H ) if termSizeChanged { log . Debugf ( " " , sess . TerminalParams , winSize ) err = s . term . setWinsize ( sess . TerminalParams ) } return err } tick := time . NewTicker ( defaults . TerminalSizeRefreshPeriod ) defer tick . Stop ( ) for { if err := sync ( ) ; err != nil { log . Infof ( " " , err ) errCount ++ if errCount > maxTermSyncErrorCount { return } } else { errCount = 0 } select { case <- s . closeC : log . Infof ( " " ) return case <- tick . C : } } }
pollAndSync is a loop inside a goroutite which keeps synchronizing the terminal
size to what's in the session (so all connected parties have the same terminal size)
it also updates 'active' field on the session.
pollAndSync is a loop inside a goroutite which keeps synchronizing the terminal size to what ' s in the session ( so all connected parties have the same terminal size ) it also updates ' active ' field on the session .
// if the error count keeps going up, this means we're stuck in // a bad state: end this goroutine to avoid leaks