<commit_before>
/**
 * Module dependencies.
 */

var EventEmitter = require('events').EventEmitter
  , IOWatcher = process.binding('io_watcher').IOWatcher
  , zmq = require('./build/default/binding')
  , util = require('util');

/**
 * Expose bindings as the module.
 */

exports = module.exports = zmq;

var types = exports.types = {
    pub: zmq.ZMQ_PUB
  , sub: zmq.ZMQ_SUB
  , req: zmq.ZMQ_REQ
  , xreq: zmq.ZMQ_XREQ
  , rep: zmq.ZMQ_REP
  , xrep: zmq.ZMQ_XREP
  , push: zmq.ZMQ_PUSH
  , pull: zmq.ZMQ_PULL
  , dealer: zmq.ZMQ_DEALER
  , router: zmq.ZMQ_ROUTER
  , pair: zmq.ZMQ_PAIR
};

// Context management happens here. We lazily initialize a default context,
// and use that everywhere. Also cleans up on exit.
var context_ = null;
var defaultContext = function() {
  if (context_ !== null) {
    return context_;
  }

  var io_threads = 1;
  if (process.env.ZMQ_IO_THREADS) {
    io_threads = parseInt(process.env.ZMQ_IO_THREADS, 10);
    if (!io_threads || io_threads < 1) {
      util.error('Invalid number in ZMQ_IO_THREADS, using 1 IO thread.');
      io_threads = 1;
    }
  }

  context_ = new zmq.Context(io_threads);
  process.on('exit', function() {
    // context_.close();
    context_ = null;
  });

  return context_;
};

// The socket type returned by `createSocket`. Wraps the low-level ZMQ binding
// with all the conveniences.
var Socket = function(typename) {
  var self = this,
    typecode = typename;

  if (typeof(typecode) !== 'number') {
    typecode = types[typename];
    if (!types.hasOwnProperty(typename) || typecode === undefined) {
      throw new TypeError("Unknown socket type: " + typename);
    }
  }

  self.type = typename;
  self._zmq = new zmq.Socket(defaultContext(), typecode);
  self._outgoing = [];
  self._watcher = new IOWatcher();
  self._watcher.callback = function() { self._flush(); };
  self._watcher.set(self._fd, true, false);
  self._watcher.start();
  self._inFlush = false;
};

/**
 * Inherit from `EventEmitter.prototype`.
 */

Socket.prototype.__proto__ = EventEmitter.prototype;

Socket.prototype.setsockopt = function(opt, val){
  this._zmq.setsockopt(opt, val);
  return this;
};

Socket.prototype.getsockopt = function(opt){
  return this._zmq.getsockopt(opt);
};
<commit_msg>clean up Socket constructor<commit_after>
/**
 * Module dependencies.
 */

var EventEmitter = require('events').EventEmitter
  , IOWatcher = process.binding('io_watcher').IOWatcher
  , zmq = require('./build/default/binding')
  , util = require('util');

/**
 * Expose bindings as the module.
 */

exports = module.exports = zmq;

/**
 * Map of socket types.
 */

var types = exports.types = {
    pub: zmq.ZMQ_PUB
  , sub: zmq.ZMQ_SUB
  , req: zmq.ZMQ_REQ
  , xreq: zmq.ZMQ_XREQ
  , rep: zmq.ZMQ_REP
  , xrep: zmq.ZMQ_XREP
  , push: zmq.ZMQ_PUSH
  , pull: zmq.ZMQ_PULL
  , dealer: zmq.ZMQ_DEALER
  , router: zmq.ZMQ_ROUTER
  , pair: zmq.ZMQ_PAIR
};

// Context management happens here. We lazily initialize a default context,
// and use that everywhere. Also cleans up on exit.
var context_ = null;
var defaultContext = function() {
  if (context_ !== null) {
    return context_;
  }

  var io_threads = 1;
  if (process.env.ZMQ_IO_THREADS) {
    io_threads = parseInt(process.env.ZMQ_IO_THREADS, 10);
    if (!io_threads || io_threads < 1) {
      util.error('Invalid number in ZMQ_IO_THREADS, using 1 IO thread.');
      io_threads = 1;
    }
  }

  context_ = new zmq.Context(io_threads);
  process.on('exit', function() {
    // context_.close();
    context_ = null;
  });

  return context_;
};

// The socket type returned by `createSocket`. Wraps the low-level ZMQ binding
// with all the conveniences.
function Socket(type) {
  var self = this;
  this.type = type;
  this._zmq = new zmq.Socket(defaultContext(), types[type]);
  this._outgoing = [];
  this._watcher = new IOWatcher;
  this._watcher.callback = function() { self._flush(); };
  this._watcher.set(self._fd, true, false);
  this._watcher.start();
  this._inFlush = false;
};

/**
 * Inherit from `EventEmitter.prototype`.
 */

Socket.prototype.__proto__ = EventEmitter.prototype;

Socket.prototype.setsockopt = function(opt, val){
  this._zmq.setsockopt(opt, val);
  return this;
};

Socket.prototype.getsockopt = function(opt){
  return this._zmq.getsockopt(opt);
};

{'fraction_non_alphanumeric': 0.14202425373134328, 'fraction_numerical': 0.002798507462686567, 'mean_word_length': 3.4584199584199586, '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': '7667115', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1531, 'n_words': 349}