net listen should emit eaddrinuse error

This commit is contained in:
Johan Euphrosine 2010-10-06 19:18:08 +02:00 committed by Ryan Dahl
parent b14eeb3c1e
commit 5d400cfd3a
2 changed files with 21 additions and 4 deletions

View File

@ -1189,10 +1189,13 @@ Server.prototype._startWatcher = function () {
};
Server.prototype._doListen = function () {
listen(this.fd, this._backlog || 128);
this._startWatcher();
};
try {
listen(this.fd, this._backlog || 128);
this._startWatcher();
} catch (err) {
this.emit('error', err);
}
}
Server.prototype.address = function () {

View File

@ -0,0 +1,14 @@
common = require('../common');
assert = common.assert
net = require('net');
var server1 = net.createServer(function (socket) {
});
var server2 = net.createServer(function (socket) {
});
server1.listen(31337);
server2.addListener('error', function(error) {
assert.equal(true, error.message.indexOf('EADDRINUSE') >= 0);
server1.close();
});
server2.listen(31337);