Determine if keepalive is desired by the client that generated this request
489643
function isKeepalive(req) {
  var conn = req.headers.connection;
  if (typeof(conn) === 'undefined' || conn === null)
    conn = '';
  conn = conn.trim().toLowerCase();

  if (/\bclose\b/i.test(conn))
    return false;
  if (/\bkeep-alive\b/i.test(conn))
    return true;

  // No Connection header. Default to keepalive for 1.1, non for 1.0.
  if (req.httpVersionMajor < 1 || req.httpVersionMinor < 1) {
    return false;
  } else {
    return true;
  }
}
63628
def set_keepalive(self, interval):
        
        pinger = functools.partial(self.ping, 'keep-alive')
        self.reactor.scheduler.execute_every(period=interval, func=pinger)
560596
public static void if_keepAliveRequest_then_resumeReading_else_closeOnComplete(
            final HttpRequest request, final Channel channel, final ChannelFuture channelFuture
    ) {
        // TODO:
        // Add Connection: Close, or Keep-Alive?
        // res.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
        if (HttpUtil.isKeepAlive(request)) {
            channelFuture.addListener(new ChannelFutureListener() {
                public void operationComplete(ChannelFuture future) {
                    resumeReading(channel);
                }
            });
        } else {
            channelFuture.addListener(ChannelFutureListener.CLOSE);
        }
    }
72027
public Boolean isKeepAlive(boolean useDefault) {

        if (m_keepAlive != null) {
            return m_keepAlive;
        }
        if (useDefault) {
            return Boolean.TRUE;
        } else {
            return null;
        }

    }
771920
public void checkInactiveSession(Session session) {
        if (session == null) {
            return;
        }
        if (log.isDebugEnabled()) {
            log.debug("Checking for idle " +  session.getId());
        }
        try (Lock ignored = session.lock()) {
            if (getEvictionPolicy() > 0 && session.isIdleLongerThan(getEvictionPolicy()) &&
                    session.isValid() && session.isResident() && session.getRequests() <= 0) {
                // Be careful with saveOnInactiveEviction - you may be able to re-animate a session that was
                // being managed on another node and has expired.
                try {
                    if (log.isDebugEnabled()) {
                        log.debug("Evicting idle session " + session.getId());
                    }

                    // save before evicting
                    if (isSaveOnInactiveEviction() && sessionDataStore != null) {
                        if (sessionDataStore.isPassivating()) {
                            sessionHandler.willPassivate(session);
                        }
                        sessionDataStore.store(session.getId(), session.getSessionData());
                    }

                    doDelete(session.getId()); // detach from this cache
                    session.setResident(false);
                } catch (Exception e) {
                    log.warn("Passivation of idle session" + session.getId() + " failed", e);
                    session.updateInactivityTimer();
                }
            }
        }
    }
232172
public NettyServerBuilder keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit) {
    checkArgument(keepAliveTimeout > 0L, "keepalive timeout must be positive");
    keepAliveTimeoutInNanos = timeUnit.toNanos(keepAliveTimeout);
    keepAliveTimeoutInNanos =
        KeepAliveManager.clampKeepAliveTimeoutInNanos(keepAliveTimeoutInNanos);
    if (keepAliveTimeoutInNanos < MIN_KEEPALIVE_TIMEOUT_NANO) {
      // Bump keepalive timeout.
      keepAliveTimeoutInNanos = MIN_KEEPALIVE_TIMEOUT_NANO;
    }
    return this;
  }
1170765
def mark_as_executed(self, req: Request):
        
        state = self[req.key]
        state.executed = True
        self._clean(state)
942548
public function keepAlive()
        {
            while (is_resource($this->fd)) {
                if ($this->session['heartbeat_timeout'] > 0 && $this->session['heartbeat_timeout'] + $this->heartbeatStamp - 5 < time()) {
                    $this->send(self::TYPE_HEARTBEAT);
                    $this->heartbeatStamp = time();
                }

                $r = array($this->fd);
                $w = $e = null;

                if (stream_select($r, $w, $e, 5) == 0) {
                    continue;
                }

                $res    = $this->read();
                $sess   = explode(':', $res);

                if ((int) Arrays::first($sess) === self::TYPE_EVENT) {
                    unset(Arrays::first($sess), $sess[1], $sess[2]);

                    $response = json_decode(implode(':', $sess), true);
                    $name = $response['name'];
                    $data = Arrays::first($response['args']);

                    $this->stdout('debug', 'Receive event "' . $name . '" with data "' . $data . '"');

                    if (!empty($this->callbacks[$name])) {
                        foreach ($this->callbacks[$name] as $callback) {
                            call_user_func($callback, $data);
                        }
                    }
                }
            }
        }
1040612
function checkIfAnotherSessionInProgress() {
        var result = $.Deferred();
        if(updateJsonHandler) {
            var state = updateJsonHandler.state;

            updateJsonHandler.refresh()
                .done(function() {
                    var val = updateJsonHandler.get(updateProgressKey);
                    if(val !== null) {
                        result.resolve(val);
                    } else {
                        result.reject();
                    }
                })
                .fail(function() {
                    updateJsonHandler.state = state;
                    result.reject();
                });
        }
        return result.promise();
    }
409106
public function keepalive() : bool
    {
        $this->reloadPids();

        // if already running don't do anything:
        if ($this->managerIsRunning() === true) {
            return false;
        }

        // if there are no workers at all do a fresh start:
        if (empty($this->pids)) {
            $this->start();
            return true;
        }

        // startup new workers if necessary:
        $this->adjustRunningWorkers();

        // delete old pid files:
        $this->reloadPids();

        return true;
    }
905123
def get_save_request_from_user(self):
        """"""

        msg = _("There are unsaved changes.\nDo you want to save?")

        dlg = GMD.GenericMessageDialog(
            self.main_window, msg,
            _("Unsaved changes"), wx.YES_NO | wx.ICON_QUESTION | wx.CANCEL)

        save_choice = dlg.ShowModal()

        dlg.Destroy()

        if save_choice == wx.ID_YES:
            return True

        elif save_choice == wx.ID_NO:
            return False
1054655
private boolean enableKeepalive(PollController conn,
                                  boolean isNew)
      throws IOException
  {
    
    if (_selectMax <= _connectionCount.get()) {
      throw new IllegalStateException(this + " keepalive overflow "
                                      + _connectionCount + " max=" + _selectMax);

      /*
      conn.requestDestroy();

      return false;
      */
    }

    JniSocketImpl socket = (JniSocketImpl) conn.getSocket();

    if (socket == null) {
      throw new IllegalStateException(this + " socket empty for " + conn);
    }

    int nativeFd = socket.getNativeFd();

    if (nativeFd < 0) {
      throw new IllegalStateException(this + " attempted keepalive with closed file descriptor fd=" + nativeFd
                                      + "\n " + socket
                                      + "\n " + conn);
    }
    else if (_connections.length() <= nativeFd) {
      throw new IllegalStateException(this + " select overflow for file descriptor fd=" + nativeFd + " " + conn);
    }

    if (! _lifecycle.isActive()) {
      throw new IllegalStateException("inactive keepalive");
    }

    if (isNew) {
      setMaxConnection(nativeFd);

      _connections.set(nativeFd, conn);

      _connectionCount.incrementAndGet();
    }

    int result = addNative(_fd, nativeFd, isNew);

    // result < 0 would likely be a disconnect

    return result == 0;
  }
258671
function ensureValidJWTCookie(request) {
    const originalRequest = request;
    const isAuthUrl = authenticatedAPIClient.isAuthUrl(originalRequest.url);
    const accessToken = authenticatedAPIClient.getDecodedAccessToken();
    const tokenExpired = authenticatedAPIClient.isAccessTokenExpired(accessToken);
    if (isAuthUrl || !tokenExpired) {
      return request;
    }

    if (!queueRequests) {
      queueRequests = true;
      authenticatedAPIClient.refreshAccessToken()
        .then(() => {
          queueRequests = false;
          PubSub.publishSync(ACCESS_TOKEN_REFRESH, { success: true });
        })
        .catch((error) => {
          // If no callback is supplied frontend-auth will (ultimately) redirect the user to login.
          // The user is redirected to logout to ensure authentication clean-up, which in turn
          // redirects to login.
          if (authenticatedAPIClient.handleRefreshAccessTokenFailure) {
            authenticatedAPIClient.handleRefreshAccessTokenFailure(error);
          } else {
            authenticatedAPIClient.logout();
          }
          PubSub.publishSync(ACCESS_TOKEN_REFRESH, { success: false });
        });
    }

    return new Promise((resolve, reject) => {
      logInfo(`Queuing API request ${originalRequest.url} while access token is refreshed`);
      PubSub.subscribeOnce(ACCESS_TOKEN_REFRESH, (msg, { success }) => {
        if (success) {
          logInfo(`Resolving queued API request ${originalRequest.url}`);
          resolve(originalRequest);
        } else {
          reject(originalRequest);
        }
      });
    });
  }
281161
@Override
  public OkHttpChannelBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit) {
    Preconditions.checkArgument(keepAliveTime > 0L, "keepalive time must be positive");
    keepAliveTimeNanos = timeUnit.toNanos(keepAliveTime);
    keepAliveTimeNanos = KeepAliveManager.clampKeepAliveTimeInNanos(keepAliveTimeNanos);
    if (keepAliveTimeNanos >= AS_LARGE_AS_INFINITE) {
      // Bump keepalive time to infinite. This disables keepalive.
      keepAliveTimeNanos = KEEPALIVE_TIME_NANOS_DISABLED;
    }
    return this;
  }
22605
function _shouldDeliverToObserver(activeChanges, acceptList, changeType) {
        var doesAccept = false;
        if (acceptList) {
            for (var i = 0, l = acceptList.length; i < l; i++) {
                var accept = acceptList[i];
                if (activeChanges[accept] > 0) {
                    return false;
                }
                if (accept === changeType) {
                    doesAccept = true;
                }
            }
        }
        return doesAccept;
    }
891549
function keepAlive(k) {
	if (k) {
		if (++keepAliveIntervalCount === 1) {
			// The actual duration doesn't really matter: it should be large but not too large.
			keepAliveIntervalId = setInterval(() => { }, 24 * 60 * 60 * 1000);
		}
	} else {
		if (--keepAliveIntervalCount === 0) {
			clearInterval(keepAliveIntervalId);
		}
	}
	debug(`keepAlive(${k}) => ${keepAliveIntervalCount}`);
}
1155160
function ensureClient(client) {
  var err;

  if(!client) {
    // Likely close() was called and now another step is happening
    // when it shouldn't. Create and log an error, so we get a stack
    // and can see why it happened.
    err = new Error('expected this.client to exist');
    log.error(err);
  }

  // If we're in an unexpected state for syncing (i.e., not a sync step), log that
  switch(client.state) {
    case ServerStates.CREATED:
    case ServerStates.CLOSED:
    case ServerStates.CLOSING:
    case ServerStates.CONNECTING:
    case ServerStates.ERROR:
      log.warn({client: client}, 'Unexpected client state for sync protocol handling: %s', client.state);
      break;
  }

  return client;
}