[Pkg-javascript-commits] [node-ws] 01/03: Imported Upstream version 1.0.0+ds1.e6ddaae4
Ximin Luo
infinity0 at debian.org
Sun Jan 3 22:47:21 UTC 2016
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository node-ws.
commit e1572a969fdd66efdd6f0086880fb5b083731dc5
Author: Ximin Luo <infinity0 at debian.org>
Date: Sun Jan 3 23:39:48 2016 +0100
Imported Upstream version 1.0.0+ds1.e6ddaae4
---
.travis.yml | 17 ++---------------
README.md | 17 +++++++++++++++++
lib/PerMessageDeflate.js | 37 +++++++++++++++++++++++++++++++++++--
lib/Receiver.js | 6 +++---
lib/WebSocket.js | 15 +++++++++++----
lib/WebSocketServer.js | 9 ++++++---
lib/browser.js | 43 -------------------------------------------
package.json | 20 ++++++--------------
test/WebSocket.test.js | 13 +++++--------
test/WebSocketServer.test.js | 14 +++++---------
10 files changed, 90 insertions(+), 101 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 820f8c9..5002b49 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,15 +1,9 @@
language: node_js
sudo: false
-npm_args: --ws:native
node_js:
- - "iojs-v3"
- - "iojs-v2"
- - "iojs-v1"
+ - "5"
+ - "4"
- "0.12"
- - "0.11"
- - "0.10"
- - "0.9"
- - "0.8"
addons:
apt:
sources:
@@ -19,10 +13,3 @@ addons:
- g++-4.9
before_install:
- export CC="gcc-4.9" CXX="g++-4.9"
- - "if [[ $(node --version) == v0.8.* ]]; then npm install -g npm at 2.1.18; fi"
-matrix:
- fast_finish: true
- allow_failures:
- - node_js: "0.11"
- - node_js: "0.9"
- - node_js: "0.8"
diff --git a/README.md b/README.md
index 9647d08..9be2e51 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,23 @@ for the full reports.
npm install --save ws
```
+### Opt-in for performance
+
+There are 2 optional modules that can be installed along side with the `ws`
+module. These modules are binary addons which improve certain operations, but as
+they are binary addons they require compilation which can fail if no c++
+compiler is installed on the host system.
+
+- `npm install --save bufferutil`: Improves internal buffer operations which
+ allows for faster processing of masked WebSocket frames and general buffer
+ operations.
+- `npm install --save utf-8-validate`: The specification requires validation of
+ invalid UTF-8 chars, some of these validations could not be done in JavaScript
+ hence the need for a binary addon. In most cases you will already be
+ validating the input that you receive for security purposes leading to double
+ validation. But if you want to be 100% spec conform and fast validation of UTF-8
+ then this module is a must.
+
### Sending and receiving text data
```js
diff --git a/lib/PerMessageDeflate.js b/lib/PerMessageDeflate.js
index b1fd743..5324bd8 100644
--- a/lib/PerMessageDeflate.js
+++ b/lib/PerMessageDeflate.js
@@ -69,6 +69,31 @@ PerMessageDeflate.prototype.accept = function(paramsList) {
};
/**
+ * Releases all resources used by the extension
+ *
+ * @api public
+ */
+
+PerMessageDeflate.prototype.cleanup = function() {
+ if (this._inflate) {
+ if (this._inflate.writeInProgress) {
+ this._inflate.pendingClose = true;
+ } else {
+ if (this._inflate.close) this._inflate.close();
+ this._inflate = null;
+ }
+ }
+ if (this._deflate) {
+ if (this._deflate.writeInProgress) {
+ this._deflate.pendingClose = true;
+ } else {
+ if (this._deflate.close) this._deflate.close();
+ this._deflate = null;
+ }
+ }
+};
+
+/**
* Accept extension offer from client
*
* @api private
@@ -207,6 +232,7 @@ PerMessageDeflate.prototype.decompress = function (data, fin, callback) {
windowBits: 'number' === typeof maxWindowBits ? maxWindowBits : DEFAULT_WINDOW_BITS
});
}
+ this._inflate.writeInProgress = true;
var self = this;
var buffers = [];
@@ -231,9 +257,12 @@ PerMessageDeflate.prototype.decompress = function (data, fin, callback) {
}
function cleanup() {
+ if (!self._inflate) return;
self._inflate.removeListener('error', onError);
self._inflate.removeListener('data', onData);
- if (fin && self.params[endpoint + '_no_context_takeover']) {
+ self._inflate.writeInProgress = false;
+ if ((fin && self.params[endpoint + '_no_context_takeover']) || self._inflate.pendingClose) {
+ if (self._inflate.close) self._inflate.close();
self._inflate = null;
}
}
@@ -256,6 +285,7 @@ PerMessageDeflate.prototype.compress = function (data, fin, callback) {
memLevel: this._options.memLevel || DEFAULT_MEM_LEVEL
});
}
+ this._deflate.writeInProgress = true;
var self = this;
var buffers = [];
@@ -281,9 +311,12 @@ PerMessageDeflate.prototype.compress = function (data, fin, callback) {
}
function cleanup() {
+ if (!self._deflate) return;
self._deflate.removeListener('error', onError);
self._deflate.removeListener('data', onData);
- if (fin && self.params[endpoint + '_no_context_takeover']) {
+ self._deflate.writeInProgress = false;
+ if ((fin && self.params[endpoint + '_no_context_takeover']) || self._deflate.pendingClose) {
+ if (self._deflate.close) self._deflate.close();
self._deflate = null;
}
}
diff --git a/lib/Receiver.js b/lib/Receiver.js
index ff4590d..b3183bf 100644
--- a/lib/Receiver.js
+++ b/lib/Receiver.js
@@ -26,7 +26,7 @@ function Receiver (extensions) {
return db.used + length;
}, function(db) {
return fragmentedPoolPrevUsed = fragmentedPoolPrevUsed >= 0 ?
- (fragmentedPoolPrevUsed + db.used) / 2 :
+ Math.ceil((fragmentedPoolPrevUsed + db.used) / 2) :
db.used;
});
@@ -36,7 +36,7 @@ function Receiver (extensions) {
return db.used + length;
}, function(db) {
return unfragmentedPoolPrevUsed = unfragmentedPoolPrevUsed >= 0 ?
- (unfragmentedPoolPrevUsed + db.used) / 2 :
+ Math.ceil((unfragmentedPoolPrevUsed + db.used) / 2) :
db.used;
});
@@ -245,7 +245,7 @@ Receiver.prototype.processPacket = function (data) {
Receiver.prototype.endPacket = function() {
if (!this.state.fragmentedOperation) this.unfragmentedBufferPool.reset(true);
- else if (this.state.lastFragment) this.fragmentedBufferPool.reset(false);
+ else if (this.state.lastFragment) this.fragmentedBufferPool.reset(true);
this.expectOffset = 0;
this.expectBuffer = null;
this.expectHandler = null;
diff --git a/lib/WebSocket.js b/lib/WebSocket.js
index 3d9c3f1..b80cc78 100644
--- a/lib/WebSocket.js
+++ b/lib/WebSocket.js
@@ -45,7 +45,7 @@ var closeTimeout = 30 * 1000; // Allow 30 seconds to terminate the connection cl
*/
function WebSocket(address, protocols, options) {
if (this instanceof WebSocket === false) {
- throw new TypeError("Classes can't be function-called");
+ return new WebSocket(address, protocols, options);
}
EventEmitter.call(this);
@@ -918,9 +918,10 @@ function cleanupWebsocketResources(error) {
this._closeTimer = null;
if (emitClose) {
- // If the connection was closed abnormally (with an error),
- // then the close code must default to 1006.
- if (error) {
+ // If the connection was closed abnormally (with an error), or if
+ // the close control frame was not received then the close code
+ // must default to 1006.
+ if (error || !this._closeReceived) {
this._closeCode = 1006;
}
this.emit('close', this._closeCode || 1000, this._closeMessage || '');
@@ -952,6 +953,12 @@ function cleanupWebsocketResources(error) {
this._receiver = null;
}
+ if (this.extensions[PerMessageDeflate.extensionName]) {
+ this.extensions[PerMessageDeflate.extensionName].cleanup();
+ }
+
+ this.extensions = null;
+
this.removeAllListeners();
this.on('error', function onerror() {}); // catch all errors after this
delete this._queue;
diff --git a/lib/WebSocketServer.js b/lib/WebSocketServer.js
index b5f82db..ba0e4c0 100644
--- a/lib/WebSocketServer.js
+++ b/lib/WebSocketServer.js
@@ -21,7 +21,7 @@ var util = require('util')
function WebSocketServer(options, callback) {
if (this instanceof WebSocketServer === false) {
- throw new TypeError("Classes can't be function-called");
+ return new WebSocketServer(options, callback);
}
events.EventEmitter.call(this);
@@ -107,7 +107,7 @@ util.inherits(WebSocketServer, events.EventEmitter);
* @api public
*/
-WebSocketServer.prototype.close = function() {
+WebSocketServer.prototype.close = function(callback) {
// terminate all associated clients
var error = null;
try {
@@ -136,7 +136,10 @@ WebSocketServer.prototype.close = function() {
finally {
delete this._server;
}
- if (error) throw error;
+ if(callback)
+ callback(error);
+ else if(error)
+ throw error;
}
/**
diff --git a/lib/browser.js b/lib/browser.js
deleted file mode 100644
index 8d3a755..0000000
--- a/lib/browser.js
+++ /dev/null
@@ -1,43 +0,0 @@
-
-/**
- * Module dependencies.
- */
-
-var global = (function() { return this; })();
-
-/**
- * WebSocket constructor.
- */
-
-var WebSocket = global.WebSocket || global.MozWebSocket;
-
-/**
- * Module exports.
- */
-
-module.exports = WebSocket ? ws : null;
-
-/**
- * WebSocket constructor.
- *
- * The third `opts` options object gets ignored in web browsers, since it's
- * non-standard, and throws a TypeError if passed to the constructor.
- * See: https://github.com/einaros/ws/issues/227
- *
- * @param {String} uri
- * @param {Array} protocols (optional)
- * @param {Object) opts (optional)
- * @api public
- */
-
-function ws(uri, protocols, opts) {
- var instance;
- if (protocols) {
- instance = new WebSocket(uri, protocols);
- } else {
- instance = new WebSocket(uri);
- }
- return instance;
-}
-
-if (WebSocket) ws.prototype = WebSocket.prototype;
diff --git a/package.json b/package.json
index 67ffb1a..3c89851 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"author": "Einar Otto Stangvik <einaros at gmail.com> (http://2x.io)",
"name": "ws",
"description": "simple to use, blazing fast and thoroughly tested websocket client, server and console for node.js, up-to-date against RFC-6455",
- "version": "0.8.0",
+ "version": "1.0.0",
"license": "MIT",
"keywords": [
"Hixie",
@@ -24,23 +24,15 @@
"options": ">=0.0.5",
"ultron": "1.0.x"
},
- "optionalDependencies": {
- "bufferutil": "1.2.x",
- "utf-8-validate": "1.2.x"
- },
"devDependencies": {
"ansi": "0.3.x",
"benchmark": "0.3.x",
+ "bufferutil": "1.2.x",
"expect.js": "0.3.x",
- "mocha": "2.2.x",
- "should": "4.3.x",
- "tinycolor": "0.0.x"
- },
- "browser": "./lib/browser.js",
- "component": {
- "scripts": {
- "ws/index.js": "./lib/browser.js"
- }
+ "mocha": "2.3.x",
+ "should": "8.0.x",
+ "tinycolor": "0.0.x",
+ "utf-8-validate": "1.2.x"
},
"gypfile": true
}
diff --git a/test/WebSocket.test.js b/test/WebSocket.test.js
index 0c5ea0d..038c7f2 100644
--- a/test/WebSocket.test.js
+++ b/test/WebSocket.test.js
@@ -40,14 +40,11 @@ describe('WebSocket', function() {
done();
}
});
- it('throws TypeError when called without new', function(done) {
- try {
- var ws = WebSocket('ws://localhost:' + port);
- }
- catch (e) {
- e.should.be.instanceof(TypeError);
- done();
- }
+
+ it('should return a new instance if called without new', function(done) {
+ var ws = WebSocket('ws://localhost:' + port);
+ ws.should.be.an.instanceOf(WebSocket);
+ done();
});
});
diff --git a/test/WebSocketServer.test.js b/test/WebSocketServer.test.js
index a300db7..210a1ad 100644
--- a/test/WebSocketServer.test.js
+++ b/test/WebSocketServer.test.js
@@ -26,16 +26,12 @@ function areArraysEqual(x, y) {
describe('WebSocketServer', function() {
describe('#ctor', function() {
- it('throws TypeError when called without new', function(done) {
- try {
- var ws = WebSocketServer({noServer: true});
- }
- catch (e) {
- e.should.be.instanceof(TypeError);
- done();
- }
+ it('should return a new instance if called without new', function(done) {
+ var ws = WebSocketServer({noServer: true});
+ ws.should.be.an.instanceOf(WebSocketServer);
+ done();
});
-
+
it('throws an error if no option object is passed', function() {
var gotException = false;
try {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-ws.git
More information about the Pkg-javascript-commits
mailing list