Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose bufferedAmount #168

Merged
merged 4 commits into from Mar 31, 2013
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -271,6 +271,18 @@ WebSocket.prototype.terminate = function() {
}
};

/**
* Expose bufferedAmount
*
* @api public
*/

Object.defineProperty(WebSocket.prototype, 'bufferedAmount', {
get: function get() {
return this._socket ? this._socket.bufferSize : 0;
}
});

/**
* Emulates the W3C Browser based WebSocket interface using function members.
*
@@ -80,6 +80,38 @@ describe('WebSocket', function() {
});
});

describe('#bufferedAmount', function() {
it('defaults to zero', function(done) {
server.createServer(++port, function(srv) {
var url = 'ws://localhost:' + port;
var ws = new WebSocket(url);
assert.equal(0, ws.bufferedAmount);
ws.terminate();
ws.on('close', function() {
srv.close();
done();
});
});
});

it('stress kernel write buffer', function(done) {
var wss = new WebSocketServer({port: ++port}, function() {
var ws = new WebSocket('ws://localhost:' + port);
});
wss.on('connection', function(ws) {
while (true) {
if (ws.bufferedAmount > 0) break;
ws.send((new Array(10000)).join('hello'));
}
ws.terminate();
ws.on('close', function() {
wss.close();
done();
});
});
});
});

describe('#readyState', function() {
it('defaults to connecting', function(done) {
server.createServer(++port, function(srv) {