Permalink
Browse files

Merge pull request #176 from 3rd-Eden/master

Emit the close event before destroying the internal _socket
  • Loading branch information...
2 parents 878d67e + 077d3de commit fa6b32304721f170c8d97bb1682c4c48fd1311f7 @einaros einaros committed Apr 9, 2013
Showing with 7 additions and 7 deletions.
  1. +7 −7 lib/WebSocket.js
View
@@ -408,7 +408,7 @@ function initAsClient(address, options) {
protocolVersion: protocolVersion,
host: null,
protocol: null,
-
+
// ssl-related options
pfx: null,
key: null,
@@ -472,28 +472,28 @@ function initAsClient(address, options) {
if (isNodeV4) {
throw new Error('Client side certificates are not supported on Node 0.4.x');
}
-
+
requestOptions.pfx = options.value.pfx;
requestOptions.key = options.value.key;
requestOptions.passphrase = options.value.passphrase;
requestOptions.cert = options.value.cert;
requestOptions.ca = options.value.ca;
requestOptions.ciphers = options.value.ciphers;
requestOptions.rejectUnauthorized = options.value.rejectUnauthorized;
-
+
// global agent ignores client side certificates
agent = new httpObj.Agent(requestOptions);
}
-
+
if (isNodeV4) {
requestOptions.path = (serverUrl.pathname || '/') + (serverUrl.search || '');
}
else requestOptions.path = serverUrl.path || '/';
-
+
if (agent) {
requestOptions.agent = agent;
}
-
+
if (isUnixSocket) {
requestOptions.socketPath = serverUrl.pathname;
}
@@ -667,6 +667,7 @@ function cleanupWebsocketResources(error) {
this.readyState = WebSocket.CLOSED;
clearTimeout(this._closeTimer);
+ if (emitClose) this.emit('close', this._closeCode || 1000, this._closeMessage || '');
if (this._socket) {
removeAllListeners(this._socket);
@@ -690,7 +691,6 @@ function cleanupWebsocketResources(error) {
this._receiver.cleanup();
this._receiver = null;
}
- if (emitClose) this.emit('close', this._closeCode || 1000, this._closeMessage || '');
removeAllListeners(this);
this.on('error', function() {}); // catch all errors after this
delete this._queue;

0 comments on commit fa6b323

Please sign in to comment.