morkai / h5.modbus

Implementation of the MODBUS IP/ASCII/RTU master and slave over TCP/UDP/Serial for Node.js.
https://miracle.systems/p/h5.modbus
MIT License
28 stars 21 forks source link

Removed duplicate code: #16

Closed goranach closed 7 years ago

goranach commented 7 years ago

!!undefined == false

nodejs/lib/net.js

Object.defineProperty(Server.prototype, 'listening', { get: function() { return !!this._handle; }, configurable: true, enumerable: true });

morkai commented 7 years ago

It's not the same. The current code covers Node.js v4 (no listening property) and up.

isOpen()
{
  // Not listening. TcpListener destroyed.
  if (this.server === null)
  {
    return false;
  }

  // server.listening is available in Node.js version >=5
  if (typeof this.server.listening === 'boolean')
  {
    return this.server.listening;
  }

  // Fallback to checking for the existence of a private variable in Node.js v4
  if (typeof this.server._handle !== 'undefined')
  {
    return !!this.server._handle;
  }

  // Otherwise, assume the server is listening.
  return true;
}