Exemplo n.º 1
0
Socket.prototype.setMulticastLoopback = function(arg) {
  var err = this._handle.setMulticastLoopback(arg ? 1 : 0);
  if (err) {
    throw util.errnoException(err, 'setMulticastLoopback');
  }

  return arg; // 0.4 compatibility
};
Exemplo n.º 2
0
function onMessage(nread, handle, buf, rinfo) {
  var self = handle.owner;
  if (nread < 0) {
    return self.emit('error', util.errnoException(nread, 'recvmsg'));
  }

  rinfo.size = buf.length; // compatibility
  self.emit('message', buf, rinfo);
}
Exemplo n.º 3
0
Socket.prototype.address = function() {
  this._healthCheck();

  var out = {};
  var err = this._handle.getsockname(out);
  if (err) {
    throw util.errnoException(err, 'getsockname');
  }

  return out;
};
Exemplo n.º 4
0
Socket.prototype.setMulticastTTL = function(arg) {
  if (!(util.isNumber(arg))) {
    throw new TypeError('Argument must be a number');
  }

  var err = this._handle.setMulticastTTL(arg);
  if (err) {
    throw util.errnoException(err, 'setMulticastTTL');
  }

  return arg;
};
Exemplo n.º 5
0
Socket.prototype.dropMembership = function(multicastAddress,
                                           interfaceAddress) {
  this._healthCheck();

  if (!multicastAddress) {
    throw new Error('multicast address must be specified');
  }

  var err = this._handle.dropMembership(multicastAddress, interfaceAddress);
  if (err) {
    throw util.errnoException(err, 'dropMembership');
  }
};
Exemplo n.º 6
0
Socket.prototype.setBroadcast = function(arg) {
  var err = this._handle.setBroadcast(arg ? 1 : 0);
  if (err) {
    throw util.errnoException(err, 'setBroadcast');
  }
};
Exemplo n.º 7
0
);
assert.equal(
  util.format('%d-%j-%s', 5001, json, 'IoT.js', 'end'),
  '5001-{"first":"1st","second":"2nd"}-IoT.js end'
);
json.json = json;
assert.equal(util.format('%j', json), '[Circular]');

assert.equal(util.format('%s', '5001'), '5001');
assert.equal(util.format('%j', '5001'), '"5001"');
assert.equal(util.format('%d%d', 5001), '5001%d');
assert.equal(util.format('%s%d%s%d', 'IoT.js ', 5001), 'IoT.js 5001%s%d');
assert.equal(util.format('%d%% %s', 100, 'IoT.js'), '100% IoT.js');
assert.equal(util.format(new Error('format')), 'Error: format');

var err1 = util.errnoException(3008, 'syscall', 'original message');
assert.equal(err1 instanceof Error, true);
assert.equal(err1, 'Error: syscall error original message');
assert.equal(err1.code, 'error');
assert.equal(err1.errno, 'error');
assert.equal(err1.syscall, 'syscall');

var err2 = util.errnoException(1, 'getSyscall');
assert.equal(err2 instanceof Error, true);
assert.equal(err2, 'Error: getSyscall error');
assert.equal(err2.code, 'error');
assert.equal(err2.errno, 'error');
assert.equal(err2.syscall, 'getSyscall');


var err3 = util.exceptionWithHostPort(1,