11cb0ef41Sopenharmony_ci// Flags: --expose-internals 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { _createSocketHandle } = require('internal/dgram'); 61cb0ef41Sopenharmony_ciconst { internalBinding } = require('internal/test/binding'); 71cb0ef41Sopenharmony_ciconst UDP = internalBinding('udp_wrap').UDP; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci{ 101cb0ef41Sopenharmony_ci // Create a handle that is not bound. 111cb0ef41Sopenharmony_ci const handle = _createSocketHandle(null, null, 'udp4'); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci assert(handle instanceof UDP); 141cb0ef41Sopenharmony_ci assert.strictEqual(typeof handle.fd, 'number'); 151cb0ef41Sopenharmony_ci assert(handle.fd < 0); 161cb0ef41Sopenharmony_ci} 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci{ 191cb0ef41Sopenharmony_ci // Create a bound handle. 201cb0ef41Sopenharmony_ci const handle = _createSocketHandle(common.localhostIPv4, 0, 'udp4'); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci assert(handle instanceof UDP); 231cb0ef41Sopenharmony_ci assert.strictEqual(typeof handle.fd, 'number'); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci if (!common.isWindows) 261cb0ef41Sopenharmony_ci assert(handle.fd > 0); 271cb0ef41Sopenharmony_ci} 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci{ 301cb0ef41Sopenharmony_ci // Return an error if binding fails. 311cb0ef41Sopenharmony_ci const err = _createSocketHandle('localhost', 0, 'udp4'); 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci assert.strictEqual(typeof err, 'number'); 341cb0ef41Sopenharmony_ci assert(err < 0); 351cb0ef41Sopenharmony_ci} 36