<commit_before>'use strict';

var util = require('util');
var Connection = require('../Connection');

module.exports = UdpConnection;

/**
 * @constructor
 * @extends {Connection}
 * @param {UdpConnection.Options|object} options
 * @event error
 * @event data
 */
function UdpConnection(options)
{
  Connection.call(this);

  /**
   * @readonly
   * @type {UdpConnection.Options}
   */
  this.options = options instanceof UdpConnection.Options
    ? options
    : new UdpConnection.Options(options);

  /**
   * @private
   * @type {dgram.Socket}
   */
  this.socket = this.setUpSocket();
}

util.inherits(UdpConnection, Connection);

/**
 * @constructor
 * @param {object} options
 * @param {dgram.Socket} options.socket
 * @param {string} [options.host]
 * @param {number} [options.port]
 */
UdpConnection.Options = function(options)
{
  /**
   * @type {dgram.Socket}
   */
  this.socket = options.socket;

  /**
   * @type {string}
   */
  this.host = typeof options.host === 'string' ? options.host : '127.0.0.1';

  /**
   * @type {number}
   */
  this.port = typeof options.port === 'number' ? options.port : 502;
};

UdpConnection.prototype.destroy = function()
{
  this.removeAllListeners();

  this.options = null;

  if (this.socket !== null)
  {
    this.socket.close();
    this.socket = null;
  }
};
<commit_msg>Destroy should remove all listeners from the `dgram.Socket`.<commit_after>'use strict';

var util = require('util');
var Connection = require('../Connection');

module.exports = UdpConnection;

/**
 * @constructor
 * @extends {Connection}
 * @param {UdpConnection.Options|object} options
 * @event error
 * @event data
 */
function UdpConnection(options)
{
  Connection.call(this);

  /**
   * @readonly
   * @type {UdpConnection.Options}
   */
  this.options = options instanceof UdpConnection.Options
    ? options
    : new UdpConnection.Options(options);

  /**
   * @private
   * @type {dgram.Socket}
   */
  this.socket = this.setUpSocket();
}

util.inherits(UdpConnection, Connection);

/**
 * @constructor
 * @param {object} options
 * @param {dgram.Socket} options.socket
 * @param {string} [options.host]
 * @param {number} [options.port]
 */
UdpConnection.Options = function(options)
{
  /**
   * @type {dgram.Socket}
   */
  this.socket = options.socket;

  /**
   * @type {string}
   */
  this.host = typeof options.host === 'string' ? options.host : '127.0.0.1';

  /**
   * @type {number}
   */
  this.port = typeof options.port === 'number' ? options.port : 502;
};

UdpConnection.prototype.destroy = function()
{
  this.removeAllListeners();

  this.options = null;

  if (this.socket !== null)
  {
    this.socket.removeAllListeners();
    this.socket.close();
    this.socket = null;
  }
};

{'fraction_non_alphanumeric': 0.1692870201096892, 'fraction_numerical': 0.006581352833638025, 'mean_word_length': 3.335974643423138, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4916553', 'n_tokens_mistral': 921, 'n_tokens_neox': 899, 'n_words': 180}