Kargi-Sitesi/node_modules/karma/lib/utils/net-utils.js

28 lines
647 B
JavaScript
Raw Normal View History

2024-11-04 02:30:09 +00:00
'use strict'
const net = require('net')
const NetUtils = {
bindAvailablePort (port, listenAddress) {
return new Promise((resolve, reject) => {
const server = net.createServer()
server
.on('error', (err) => {
server.close()
if (err.code === 'EADDRINUSE' || err.code === 'EACCES') {
server.listen(++port, listenAddress)
} else {
reject(new Error(`Failed to bind ${port}: ` + (err.stack || err)))
}
})
.on('listening', () => {
resolve(server)
})
.listen(port, listenAddress)
})
}
}
module.exports = NetUtils