|
|
@ -450,10 +450,7 @@ function Server(/* [ options, ] listener */) { |
|
|
|
this.connections = 0; |
|
|
|
this.allowHalfOpen = options.allowHalfOpen || false; |
|
|
|
|
|
|
|
|
|
|
|
this._handle = new TCP(); |
|
|
|
this._handle.socket = this; |
|
|
|
this._handle.onconnection = onconnection; |
|
|
|
this._handle = null; |
|
|
|
} |
|
|
|
util.inherits(Server, events.EventEmitter); |
|
|
|
exports.Server = Server; |
|
|
@ -465,6 +462,11 @@ function toPort(x) { return (x = Number(x)) >= 0 ? x : false; } |
|
|
|
function listenip(self, ip, port, addressType) { |
|
|
|
var r = 0; |
|
|
|
|
|
|
|
// assign handle in listen, and clean up if bind or listen fails
|
|
|
|
self._handle = new TCP(); |
|
|
|
self._handle.socket = this; |
|
|
|
self._handle.onconnection = onconnection; |
|
|
|
|
|
|
|
if (ip && port) { |
|
|
|
debug("bind to " + ip); |
|
|
|
if (addressType == 6) { |
|
|
@ -473,15 +475,28 @@ function listenip(self, ip, port, addressType) { |
|
|
|
r = self._handle.bind(ip, port); |
|
|
|
} |
|
|
|
} |
|
|
|
if (r) { |
|
|
|
self._handle.close(); |
|
|
|
self._handle = null; |
|
|
|
|
|
|
|
process.nextTick(function() { |
|
|
|
self.emit('error', errnoException(errno, 'listen')); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
r = self._handle.listen(self._backlog || 128); |
|
|
|
if (r) { |
|
|
|
self._handle.close(); |
|
|
|
self._handle = null; |
|
|
|
|
|
|
|
process.nextTick(function() { |
|
|
|
self.emit('error', errnoException(errno, 'listen')); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
self._handle.listen(self._backlog || 128); |
|
|
|
process.nextTick(function() { |
|
|
|
self.emit('listening'); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Server.prototype.listen = function() { |
|
|
@ -539,7 +554,10 @@ function onconnection(clientHandle) { |
|
|
|
|
|
|
|
|
|
|
|
Server.prototype.close = function() { |
|
|
|
if (this._handle != null) { |
|
|
|
this._handle.close(); |
|
|
|
this._handle = null; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|