Fix socket close event handling in node.js 0.11.x

Fix mcavage/node-ldapjs#205
This commit is contained in:
Patrick Mooney 2014-06-24 18:39:12 -05:00
parent ea96468602
commit b49c2efed2
1 changed files with 5 additions and 9 deletions

View File

@ -838,8 +838,8 @@ Client.prototype._connect = function _connect() {
socket.destroy();
cb(err || new Error('client error during setup'));
}
// Work around lack of close event on tls.socket
((self.secure) ? socket.socket : socket).once('close', bail);
// Work around lack of close event on tls.socket in node < 0.11
((socket.socket) ? socket.socket : socket).once('close', bail);
socket.once('error', bail);
socket.once('end', bail);
socket.once('timeout', bail);
@ -882,8 +882,8 @@ Client.prototype._connect = function _connect() {
.removeAllListeners('end')
.removeAllListeners('timeout');
// Work around lack of close event on tls.socket
((self.secure) ? socket.socket : socket).once('close',
// Work around lack of close event on tls.socket in node < 0.11
((socket.socket) ? socket.socket : socket).once('close',
self._onClose.bind(self));
socket.on('end', function onEnd() {
if (log.trace())
@ -970,11 +970,7 @@ Client.prototype._onClose = function _onClose(had_err) {
this.socket = null;
this.connected = false;
if (!this.secure) {
socket.removeAllListeners('close');
} else {
socket.socket.removeAllListeners('close');
}
((socket.socket) ? socket.socket : socket).removeAllListeners('close');
if (this.log.trace())
this.log.trace('close event had_err=%s', had_err ? 'yes' : 'no');