|
|
@ -268,14 +268,10 @@ function writeAfterFIN(chunk, encoding, cb) { |
|
|
|
// TODO: defer error events consistently everywhere, not just the cb
|
|
|
|
self.emit('error', er); |
|
|
|
if (typeof cb === 'function') { |
|
|
|
process.nextTick(writeAfterFINNT, cb, er); |
|
|
|
process.nextTick(cb, er); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function writeAfterFINNT(cb, er) { |
|
|
|
cb(er); |
|
|
|
} |
|
|
|
|
|
|
|
exports.Socket = Socket; |
|
|
|
exports.Stream = Socket; // Legacy naming.
|
|
|
|
|
|
|
@ -442,9 +438,7 @@ Socket.prototype._destroy = function(exception, cb) { |
|
|
|
function fireErrorCallbacks() { |
|
|
|
if (cb) cb(exception); |
|
|
|
if (exception && !self._writableState.errorEmitted) { |
|
|
|
process.nextTick(function() { |
|
|
|
self.emit('error', exception); |
|
|
|
}); |
|
|
|
process.nextTick(emitErrorNT, self, exception); |
|
|
|
self._writableState.errorEmitted = true; |
|
|
|
} |
|
|
|
} |
|
|
@ -962,7 +956,10 @@ function lookupAndConnect(self, options) { |
|
|
|
// immediately calls net.Socket.connect() on it (that's us).
|
|
|
|
// There are no event listeners registered yet so defer the
|
|
|
|
// error event to the next tick.
|
|
|
|
process.nextTick(connectErrorNT, self, err, options); |
|
|
|
err.host = options.host; |
|
|
|
err.port = options.port; |
|
|
|
err.message = err.message + ' ' + options.host + ':' + options.port; |
|
|
|
process.nextTick(connectErrorNT, self, err); |
|
|
|
} else { |
|
|
|
self._unrefTimer(); |
|
|
|
connect(self, |
|
|
@ -976,10 +973,7 @@ function lookupAndConnect(self, options) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function connectErrorNT(self, err, options) { |
|
|
|
err.host = options.host; |
|
|
|
err.port = options.port; |
|
|
|
err.message = err.message + ' ' + options.host + ':' + options.port; |
|
|
|
function connectErrorNT(self, err) { |
|
|
|
self.emit('error', err); |
|
|
|
self._destroy(); |
|
|
|
} |
|
|
@ -1205,9 +1199,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) { |
|
|
|
|
|
|
|
if (typeof rval === 'number') { |
|
|
|
var error = exceptionWithHostPort(rval, 'listen', address, port); |
|
|
|
process.nextTick(function() { |
|
|
|
self.emit('error', error); |
|
|
|
}); |
|
|
|
process.nextTick(emitErrorNT, self, error); |
|
|
|
return; |
|
|
|
} |
|
|
|
self._handle = rval; |
|
|
@ -1222,9 +1214,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) { |
|
|
|
var ex = exceptionWithHostPort(err, 'listen', address, port); |
|
|
|
self._handle.close(); |
|
|
|
self._handle = null; |
|
|
|
process.nextTick(function() { |
|
|
|
self.emit('error', ex); |
|
|
|
}); |
|
|
|
process.nextTick(emitErrorNT, self, ex); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -1239,6 +1229,11 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function emitErrorNT(self, err) { |
|
|
|
self.emit('error', err); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function emitListeningNT(self) { |
|
|
|
// ensure handle hasn't closed
|
|
|
|
if (self._handle) |
|
|
@ -1412,9 +1407,7 @@ function onconnection(err, clientHandle) { |
|
|
|
|
|
|
|
Server.prototype.getConnections = function(cb) { |
|
|
|
function end(err, connections) { |
|
|
|
process.nextTick(function() { |
|
|
|
cb(err, connections); |
|
|
|
}); |
|
|
|
process.nextTick(cb, err, connections); |
|
|
|
} |
|
|
|
|
|
|
|
if (!this._usingSlaves) { |
|
|
@ -1493,11 +1486,14 @@ Server.prototype._emitCloseIfDrained = function() { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
process.nextTick(function() { |
|
|
|
process.nextTick(emitCloseNT, self); |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function emitCloseNT(self) { |
|
|
|
debug('SERVER: emit close'); |
|
|
|
self.emit('close'); |
|
|
|
}); |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Server.prototype.listenFD = util.deprecate(function(fd, type) { |
|
|
|