<commit_before>
/*!
 * socket.io-node
 * Copyright(c) 2011 LearnBoost <<EMAIL>>
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var EventEmitter = require('events').EventEmitter
  , util = require('util');

/**
 * Export the constructor.
 */

module.exports = Socket;

/**
 * Default error event listener to prevent uncaught exceptions.
 */

var defaultError = function () {};

/**
 * Socket constructor.
 *
 * @param {Manager} manager instance
 * @param {String} session id
 * @param {Namespace} namespace the socket belongs to
 * @param {Boolean} whether the 
 * @api public
 */

function Socket (manager, id, handshaken) {
  EventEmitter.call(this);

  this.readyState = Socket.CONNECTED;
  this.id = id;
  this.manager = manager;
  this.ackPackets = 0;
  this.acks = {};
  this.handshaken = handshaken;
  this.store = this.manager.store;
  this.setFlags();
  this.on('error', defaultError);
}

/**
 * Inherits from EventEmitter.
 */

util.inherits(Socket, EventEmitter);

/**
 * Socket readyState
 */

Socket.CONNECTED = 0;
Socket.DISCONNECTING = 1;
Socket.DISCONNECTED = 2;

/**
 * Accessor shortcut for the handshake data
 * It is just a cache for the data in Store
 *
 * @api private
 */

Socket.prototype.__defineGetter__('handshake', function () {
  return this.handshaken;
});

/**
 * Accessor shortcut for the transport type
 *
 * @api private
 */

Socket.prototype.__defineGetter__('transport', function () {
  return this.manager.transportMap[this.id];
});

/**
 * JSON message flag.
 *
 * @api public
 */
 
Socket.prototype.__defineGetter__('json', function() {
  this.flags.json = true;
  return this;
});

/**
 * Resets flags
 *
 * @api private
 */

Socket.prototype.setFlags = function() {
  this.flags = {};
  return this;
};

/**
 * Accessor shortcut for the logger.
 *
 * @api private
 */

Socket.prototype.__defineGetter__('log', function () {
  return this.manager.log;
});

/**
 * Triggered on disconnect
 *
 * @api private
 */

Socket.prototype.onDisconnect = function (reason) {
  if (this.readyState !== Socket.DISCONNECTED) {
    this.$emit('disconnect', reason);
    this.readyState = Socket.DISCONNECTED;
  }
};

/**
 * Transmits a packet.
 *
 * @api private
 */

Socket.prototype.packet = function (packet) {
  if (this.readyState !== Socket.DISCONNECTED) {
    this.transport.packet(packet);
  }

  this.setFlags();
  return this;
};

/**<commit_msg>add debug info<commit_after>
/*!
 * socket.io-node
 * Copyright(c) 2011 LearnBoost <<EMAIL>>
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var EventEmitter = require('events').EventEmitter
  , util = require('util');

/**
 * Export the constructor.
 */

module.exports = Socket;

/**
 * Default error event listener to prevent uncaught exceptions.
 */

var defaultError = function () {};

/**
 * Socket constructor.
 *
 * @param {Manager} manager instance
 * @param {String} session id
 * @param {Namespace} namespace the socket belongs to
 * @param {Boolean} whether the 
 * @api public
 */

function Socket (manager, id, handshaken) {
  EventEmitter.call(this);

  this.readyState = Socket.CONNECTED;
  this.id = id;
  this.manager = manager;
  this.ackPackets = 0;
  this.acks = {};
  this.handshaken = handshaken;
  this.store = this.manager.store;
  this.setFlags();
  this.on('error', defaultError);
}

/**
 * Inherits from EventEmitter.
 */

util.inherits(Socket, EventEmitter);

/**
 * Socket readyState
 */

Socket.CONNECTED = 0;
Socket.DISCONNECTING = 1;
Socket.DISCONNECTED = 2;

/**
 * Accessor shortcut for the handshake data
 * It is just a cache for the data in Store
 *
 * @api private
 */

Socket.prototype.__defineGetter__('handshake', function () {
  return this.handshaken;
});

/**
 * Accessor shortcut for the transport type
 *
 * @api private
 */

Socket.prototype.__defineGetter__('transport', function () {
  return this.manager.transportMap[this.id];
});

/**
 * JSON message flag.
 *
 * @api public
 */
 
Socket.prototype.__defineGetter__('json', function() {
  this.flags.json = true;
  return this;
});

/**
 * Resets flags
 *
 * @api private
 */

Socket.prototype.setFlags = function() {
  this.flags = {};
  return this;
};

/**
 * Accessor shortcut for the logger.
 *
 * @api private
 */

Socket.prototype.__defineGetter__('log', function () {
  return this.manager.log;
});

/**
 * Triggered on disconnect
 *
 * @api private
 */

Socket.prototype.onDisconnect = function (reason) {
  if (this.readyState !== Socket.DISCONNECTED) {
    this.$emit('disconnect', reason);
    this.readyState = Socket.DISCONNECTED;
  }
};

/**
 * Transmits a packet.
 *
 * @api private
 */

Socket.prototype.packet = function (packet) {
  if (this.readyState !== Socket.DISCONNECTED) {
    this.transport.packet(packet);
  }

  this.log.debug('socket send: ', packet);
  this.setFlags();
  return this;
};

/**
{'fraction_non_alphanumeric': 0.15379825653798257, 'fraction_numerical': 0.0033208800332088003, 'mean_word_length': 3.4827906976744187, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2301827', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1572, 'n_words': 373}