|
|
@ -51,7 +51,7 @@ module.exports = class RPC { |
|
|
|
bind (port = this._bind) { |
|
|
|
if (this._binding) return this._binding |
|
|
|
|
|
|
|
const defaultPort = this._bind |
|
|
|
const self = this |
|
|
|
|
|
|
|
this._binding = new Promise((resolve, reject) => { |
|
|
|
const s = this.socket |
|
|
@ -61,16 +61,16 @@ module.exports = class RPC { |
|
|
|
s.on('error', onerror) |
|
|
|
|
|
|
|
function onlistening () { |
|
|
|
this._bound = true |
|
|
|
self._bound = true |
|
|
|
|
|
|
|
s.removeListener('listening', onlistening) |
|
|
|
s.removeListener('error', onerror) |
|
|
|
resolve() |
|
|
|
resolve(s.address().port) |
|
|
|
} |
|
|
|
|
|
|
|
function onerror (err) { |
|
|
|
// retry on any port if preferred port is unavail
|
|
|
|
if (port === defaultPort && port !== 0) { |
|
|
|
if (port === self._bind && port !== 0) { |
|
|
|
port = 0 |
|
|
|
s.bind(0) |
|
|
|
return |
|
|
|