keep the connection alive
@private method
331784
function ping (){
    clearTimeout( ping.timer );
    ping.timer = setTimeout(function(){
      b9.send({ type: 'ping', time: Date.now() });
    }, b9._interval );
  }
1221320
function () {
    if (!self.connections.length) {
      self.removeListener('remove', remove);
      self.closing = false;
      return callback();
    }
  }
1024018
function () {
        reconnectStartedAt = null;
        isConnecting = false;
        if (ortc.sockjs && ortc.sockjs != null) {
            ortc.sockjs.close();
            ortc.sockjs = null;
        }
    }
165911
function connectIfNeeded() {
      // console.log('re-establishing the connect');
      websocket = null;
      socketCreationInProcess = false;

      // The token may have expired so test for it.
      getToken(determineService())
        .then(() => {
          return processSTTSocketStart(false);
        })
        .then(() => {
          //return Promise.resolve();
          return;
        })
        .catch((err) => {
          //return Promise.resolve();
          return;
        });
    }
12302
def keep_alive(self, val: bool) -> None:
        
        self._keepalive = val
        if self._keepalive_handle:
            self._keepalive_handle.cancel()
            self._keepalive_handle = None
1062890
function persist(pErr, pVal) {
          if (pErr) {
            return cb(pErr);
          }

          if (ttl) {
            conn.setex(key, ttl, pVal, handleResponse(conn, cb));
          } else {
            conn.set(key, pVal, handleResponse(conn, cb));
          }
        }
1118696
function(f) {
    this.socket = tls.connect(this.config.tcp, f);

    this.socket.on('secureConnect', function() {
      this.isConnected = true;
      if (this.retryCount > 1) {
        this.logger.info('Logmatic - reconnected.');
      } else {
        this.logger.debug('Logmatic - connected.');
      }
      this.retryCount = 0;

      while (this.messageBuffer.length) {
        this.sendMessage(this.messageBuffer.shift());
      }
    }.bind(this));

    this.socket.on('timeout', function() {
      this.logger.warn('Logmatic - connection timed out.');
    });

    this.socket.on('error', this.logger.error.bind(this.logger));

    this.socket.on('close', function() {
      this.isConnected = false;
      this.retryCount++;

      if(this.retryCount > 1) {
        setTimeout(function() {
          this.connect();
        }.bind(this), this.config.retryTimeout);
        this.logger.error('Logmatic - failling to reconnect', this.retryCount);
      } else {
        this.connect();
        this.logger.debug('Logmatic - connection closed.');
      }
    }.bind(this));
  }
597437
function connectionDelay() {
      var delay = self.connectionWait;
      if (delay === 0) {
        if (self.connectedAt) {
          var t = 1000;
          var connectedFor = new Date().getTime() - self.connectedAt;
          if (connectedFor < t) {
            delay = t - connectedFor;
          }
        }
      }
      return delay;
    }
379301
def keep_alive(self):

		'''
		
		'''

		# keep transaction alive
		txn_response = self.api.http_request('POST','%sfcr:tx' % self.root, data=None, headers=None)

		# if 204, transaction kept alive
		if txn_response.status_code == 204:
			logger.debug("continuing transaction: %s" % self.root)
			# update status and timer
			self.active = True
			self.expires = txn_response.headers['Expires']
			return  True

		# if 410, transaction does not exist
		elif txn_response.status_code == 410:
			logger.debug("transaction does not exist: %s" % self.root)
			self.active = False
			return False

		else:
			raise Exception('HTTP %s, could not continue transaction' % txn_response.status_code)
391053
def timeout_keep_alive_handler(self):
        
        if not self.transport.is_closing():
            event = h11.ConnectionClosed()
            self.conn.send(event)
            self.transport.close()
26895
function(callback) {
      var t = this;
      callback = callback || function(){};
      var onPong = function() {
        t.off('pong', onPong);
        callback();
      };
      t.on('pong', onPong);
      t.emit('connection:ping');
    }
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;
  }
881903
function(callback) {
                connection.end();

                client.close();
                client.__sftp = null;
                client.__ssh = null;

                callback();
            }
630661
function Message(connection) {
  // Inherit from event emitter
  var that = this;
  EventEmitter.call(this);

  // Save the connection
  this.connection = connection;

  // If there is a body already, don't buffer
  if (connection.body) {
    that.body = connection.body;
    async.setImmediate(function () {
      that.emit('loaded');
    });
    return;
  }

  // Buffer the content of the connecftion
  connection.pipe(concat(function handleBuffer (buff) {
    // Save the body and emit a `loaded` event
    // DEV: The delay is so `async.waterfall` still operates when we enter it
    that.body = buff.length ? buff : '';
    async.setImmediate(function () {
      that.emit('loaded');
    });
  }));
}
139895
def alive(opts):
    '''
    
    '''
    if salt.utils.napalm.not_always_alive(opts):
        return True  # don't force reconnection for not-always alive proxies
        # or regular minion
    is_alive_ret = call('is_alive', **{})
    if not is_alive_ret.get('result', False):
        log.debug(
            '[%s] Unable to execute `is_alive`: %s',
            opts.get('id'), is_alive_ret.get('comment')
        )
        # if `is_alive` is not implemented by the underneath driver,
        # will consider the connection to be still alive
        # we don't want overly request connection reestablishment
        # NOTE: revisit this if IOS is still not stable
        #       and return False to force reconnection
        return True
    flag = is_alive_ret.get('out', {}).get('is_alive', False)
    log.debug('Is %s still alive? %s', opts.get('id'), 'Yes.' if flag else 'No.')
    return flag
598799
function() {
    
        that.connected = true;
        that.tcp_connection.setKeepAlive( true );	
        
        if ( that.message_buffer.length ) {
            while( that.message_buffer.length ) {
                that.tcp_connection.write( that.message_buffer.shift() );
            }
        }
    }
772246
function Listener() {
		// setup abstract layer
		core.ListenerAbstract.apply(this, arguments);

		var self = this;

		// in case the process die, the connection will be severed
		this.object.on('exit', function () {
			if (self.online === true) {
				this.emit('close');
			}
		});

		process.nextTick(function () {
			// setup a new connection with the object
			self.emit('listening');

			// setup a new connection with the object
			self.emit('connection', self.object);
		});
	}