11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// This tests that net.connect() from a used local port throws EADDRINUSE. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst common = require('../common'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst net = require('net'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst server1 = net.createServer(common.mustNotCall()); 101cb0ef41Sopenharmony_ciserver1.listen(0, common.localhostIPv4, common.mustCall(() => { 111cb0ef41Sopenharmony_ci const server2 = net.createServer(common.mustNotCall()); 121cb0ef41Sopenharmony_ci server2.listen(0, common.localhostIPv4, common.mustCall(() => { 131cb0ef41Sopenharmony_ci const client = net.connect({ 141cb0ef41Sopenharmony_ci host: common.localhostIPv4, 151cb0ef41Sopenharmony_ci port: server1.address().port, 161cb0ef41Sopenharmony_ci localAddress: common.localhostIPv4, 171cb0ef41Sopenharmony_ci localPort: server2.address().port 181cb0ef41Sopenharmony_ci }, common.mustNotCall()); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci client.on('error', common.mustCall((err) => { 211cb0ef41Sopenharmony_ci assert.strictEqual(err.code, 'EADDRINUSE'); 221cb0ef41Sopenharmony_ci server1.close(); 231cb0ef41Sopenharmony_ci server2.close(); 241cb0ef41Sopenharmony_ci })); 251cb0ef41Sopenharmony_ci })); 261cb0ef41Sopenharmony_ci})); 27