private StateConnection processPoll()
    throws IOException
  {
    PortTcp port = _port;

    if (port.isClosed()) {
      return StateConnection.DESTROY;
    }

    if (readStream().available() > 0) {
      return StateConnection.ACTIVE;
    }

    long timeout = _idleTimeout;

    _idleStartTime = CurrentTime.currentTime();
    _idleExpireTime = _idleStartTime + timeout;

    // _state = _state.toKeepalive(this);

    PollTcpManagerBase pollManager = port.pollManager();

    // use poll manager if available
    if (pollManager == null) {
      port().stats().addLifetimeKeepaliveCount();

      return threadPoll(timeout);
    }

    if (! _pollHandle.isKeepaliveStarted()) {
      ServiceRef.flushOutbox();

      if (_port.keepaliveThreadRead(readStream(), _idleTimeout) > 0) {
        return StateConnection.ACTIVE;
      }
      else if (_idleExpireTime <= CurrentTime.currentTime()) {
        return StateConnection.TIMEOUT;
      }
    }

    /*
    if (! _state.toPollRequested(_stateRef)) {
      return _stateRef.get().getNextState();
    }
      // _state = _state.toKeepaliveSelect();
       * */


      // keepalive to select manager succeeds
    switch (pollManager.startPoll(_pollHandle)) {
    case START: {
      if (log.isLoggable(Level.FINEST)) {
        log.finest(dbgId() + "keepalive (poll)");
      }

      port().stats().addLifetimeKeepaliveCount();
      port().stats().addLifetimeKeepalivePollCount();

      return StateConnection.POLL;
    }

    case DATA: {
      if (log.isLoggable(Level.FINEST)) {
        log.finest("keepalive data available (poll) [" + dbgId() + "]");
      }

      //_state = _state.toWake();
      //System.out.println("DATA: " + _state);
      /*
        if (_stateRef.get().toPollSleep(_stateRef)) {
          throw new IllegalStateException();
        }
       */

      return StateConnection.ACTIVE;
    }

    case CLOSED: {
      if (log.isLoggable(Level.FINEST)) {
        log.finest(dbgId() + " keepalive close (poll)");
      }

      //_state = _state.toWake();

      /*
        if (_stateRef.get().toPollSleep(_stateRef)) {
          throw new IllegalStateException();
        }
       */

      return StateConnection.CLOSE_READ_A;
    }

    default:
      throw new IllegalStateException();
    }
  }
private StateConnection processPoll ( ) throws IOException { PortTcp port = _port ; if ( port . isClosed ( ) ) { return StateConnection . DESTROY ; } if ( readStream ( ) . available ( ) > 0 ) { return StateConnection . ACTIVE ; } long timeout = _idleTimeout ; _idleStartTime = CurrentTime . currentTime ( ) ; _idleExpireTime = _idleStartTime + timeout ; PollTcpManagerBase pollManager = port . pollManager ( ) ; if ( pollManager == null ) { port ( ) . stats ( ) . addLifetimeKeepaliveCount ( ) ; return threadPoll ( timeout ) ; } if ( ! _pollHandle . isKeepaliveStarted ( ) ) { ServiceRef . flushOutbox ( ) ; if ( _port . keepaliveThreadRead ( readStream ( ) , _idleTimeout ) > 0 ) { return StateConnection . ACTIVE ; } else if ( _idleExpireTime <= CurrentTime . currentTime ( ) ) { return StateConnection . TIMEOUT ; } } switch ( pollManager . startPoll ( _pollHandle ) ) { case START : { if ( log . isLoggable ( Level . FINEST ) ) { log . finest ( dbgId ( ) + "keepalive (poll)" ) ; } port ( ) . stats ( ) . addLifetimeKeepaliveCount ( ) ; port ( ) . stats ( ) . addLifetimeKeepalivePollCount ( ) ; return StateConnection . POLL ; } case DATA : { if ( log . isLoggable ( Level . FINEST ) ) { log . finest ( "keepalive data available (poll) [" + dbgId ( ) + "]" ) ; } return StateConnection . ACTIVE ; } case CLOSED : { if ( log . isLoggable ( Level . FINEST ) ) { log . finest ( dbgId ( ) + " keepalive close (poll)" ) ; } return StateConnection . CLOSE_READ_A ; } default : throw new IllegalStateException ( ) ; } }
Starts a keepalive, either returning available data or
returning false to close the loop

If keepaliveRead() returns true, data is available.
If it returns false, either the connection is closed,
or the connection has been registered with the select.