• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const dgram = require('dgram');
5const socket = dgram.createSocket('udp4');
6
7socket.bind(0);
8socket.on('listening', common.mustCall(() => {
9  const result = socket.setTTL(16);
10  assert.strictEqual(result, 16);
11
12  assert.throws(() => {
13    socket.setTTL('foo');
14  }, {
15    code: 'ERR_INVALID_ARG_TYPE',
16    name: 'TypeError',
17    message: 'The "ttl" argument must be of type number. Received type string' +
18             " ('foo')"
19  });
20
21  // TTL must be a number from > 0 to < 256
22  assert.throws(() => {
23    socket.setTTL(1000);
24  }, /^Error: setTTL EINVAL$/);
25
26  socket.close();
27}));
28