<commit_before>var Package = require('pomelo-protocol').Package;
var logger = require('pomelo-logger').getLogger('pomelo', __filename);

/**
 * Process heartbeat request.
 *
 * @param {Object} opts option request
 *                      opts.heartbeat heartbeat interval
 */
var Command = function(opts) {
  opts = opts || {};
  this.heartbeat = null;
  this.timeout = null;

  if(opts.heartbeat) {
    this.heartbeat = opts.heartbeat * 1000; // heartbeat interval
    this.timeout = opts.timeout * 1000 || this.heartbeat * 2;      // max heartbeat message timeout
    this.heartbeatSec = opts.heartbeat
  }

  this.timeouts = {};
  this.clients = {};
  this.disconnectOnTimeout = opts.disconnectOnTimeout;
};

module.exports = Command;

Command.prototype.handle = function(socket) {
  if(!this.heartbeat) {
    // no heartbeat setting
    return;
  }

  var now = Date.now() / 1000 | 0
  if(!!socket.__hbTime__ && now - socket.__hbTime__ < this.heartbeatSec-1) {
    socket.disconnect('heartbeat too frequently')
    return
  }
  socket.__hbTime__ = now

  var self = this;

  if(!this.clients[socket.id]) {
    // clear timers when socket disconnect or error
    this.clients[socket.id] = 1;
    socket.once('disconnect', clearTimers.bind(null, this, socket.id));
    socket.once('error', clearTimers.bind(null, this, socket.id));
  }

  // clear timeout timer
  if(self.disconnectOnTimeout) {
    this.clear(socket.id);
  }

  socket.sendRaw(Package.encode(Package.TYPE_HEARTBEAT));

  if(self.disconnectOnTimeout) {
    self.timeouts[socket.id] = setTimeout(function() {
      logger.debug('client %j heartbeat timeout.', socket.id);
      socket.disconnect();
    }, self.timeout);
  }<commit_msg>hb limit change to hb - 3sec<commit_after>var Package = require('pomelo-protocol').Package;
var logger = require('pomelo-logger').getLogger('pomelo', __filename);

/**
 * Process heartbeat request.
 *
 * @param {Object} opts option request
 *                      opts.heartbeat heartbeat interval
 */
var Command = function(opts) {
  opts = opts || {};
  this.heartbeat = null;
  this.timeout = null;

  if(opts.heartbeat) {
    this.heartbeat = opts.heartbeat * 1000; // heartbeat interval
    this.timeout = opts.timeout * 1000 || this.heartbeat * 2;      // max heartbeat message timeout
    this.heartbeatSec = opts.heartbeat
  }

  this.timeouts = {};
  this.clients = {};
  this.disconnectOnTimeout = opts.disconnectOnTimeout;
};

module.exports = Command;

Command.prototype.handle = function(socket) {
  if(!this.heartbeat) {
    // no heartbeat setting
    return;
  }

  var now = Date.now() / 1000 | 0
  if(!!socket.__hbTime__ && now - socket.__hbTime__ < this.heartbeatSec-3) {
    socket.disconnect('heartbeat too frequently')
    return
  }
  socket.__hbTime__ = now

  var self = this;

  if(!this.clients[socket.id]) {
    // clear timers when socket disconnect or error
    this.clients[socket.id] = 1;
    socket.once('disconnect', clearTimers.bind(null, this, socket.id));
    socket.once('error', clearTimers.bind(null, this, socket.id));
  }

  // clear timeout timer
  if(self.disconnectOnTimeout) {
    this.clear(socket.id);
  }

  socket.sendRaw(Package.encode(Package.TYPE_HEARTBEAT));

  if(self.disconnectOnTimeout) {
    self.timeouts[socket.id] = setTimeout(function() {
      logger.debug('client %j heartbeat timeout.', socket.id);
      socket.disconnect();
    }, self.timeout);
  }
{'fraction_non_alphanumeric': 0.14009944428195378, 'fraction_numerical': 0.009651945013161743, 'mean_word_length': 3.3073047858942064, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5984199', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1065, 'n_words': 223}