1// Flags: --expose-internals 2'use strict'; 3const common = require('../common'); 4const assert = require('assert'); 5const { _createSocketHandle } = require('internal/dgram'); 6const { internalBinding } = require('internal/test/binding'); 7const UDP = internalBinding('udp_wrap').UDP; 8 9{ 10 // Create a handle that is not bound. 11 const handle = _createSocketHandle(null, null, 'udp4'); 12 13 assert(handle instanceof UDP); 14 assert.strictEqual(typeof handle.fd, 'number'); 15 assert(handle.fd < 0); 16} 17 18{ 19 // Create a bound handle. 20 const handle = _createSocketHandle(common.localhostIPv4, 0, 'udp4'); 21 22 assert(handle instanceof UDP); 23 assert.strictEqual(typeof handle.fd, 'number'); 24 25 if (!common.isWindows) 26 assert(handle.fd > 0); 27} 28 29{ 30 // Return an error if binding fails. 31 const err = _createSocketHandle('localhost', 0, 'udp4'); 32 33 assert.strictEqual(typeof err, 'number'); 34 assert(err < 0); 35} 36