handle sequence overflow (more than 65535 requests in one connection)

This commit is contained in:
Andrey Sidorov 2012-07-16 14:18:52 +10:00
parent 86152f7aaf
commit 2decda57fd
3 changed files with 51 additions and 3 deletions

View file

@ -92,8 +92,15 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs)
target[r] = (function(reqName) {
var reqFunc = function req_proxy() {
client.seq_num++; // TODO: handle overflow (seq should be last 15 (?) bits of the number
// simple overflow handling (this means that currently there is no way to have more than 65535 requests in the queue
// TODO: edge cases testing
if (client.seq_num == 65535)
client.seq_num = 0;
else
client.seq_num++;
// long stack traces. going to disable in next commit, keep it currently to compare performance
var err = new Error;
err.name = reqName;
Error.captureStackTrace(err, arguments.callee);

View file

@ -3,7 +3,7 @@
, "description": "A pure node.js JavaScript client implementing X Window (X11) protocol."
, "keywords": ["X Window", "ui", "gui", "widgets", "desktop", "XWindow", "X"]
, "homepage": "https://github.com/sidorares/node-x11"
, "version" : "0.0.7"
, "version" : "0.0.8"
, "maintainers" :
[ { "name": "Andrey Sidorov"
, "email": "sidoares@yandex.ru"
@ -23,7 +23,7 @@
"should": "*"
}
, "scripts": {
"test": "mocha",
"test": "mocha -t 30000",
"prepublish" : "npm prune"
}
}

41
test/sequence-overflow.js Normal file
View file

@ -0,0 +1,41 @@
var x11 = require('../lib/x11');
var should = require('should');
var assert = require('assert');
describe('Client', function() {
var display;
beforeEach(function(done) {
var client = x11.createClient(function(dpy) {
display=dpy;
done();
client.removeListener('error', done);
});
client.on('error', done);
});
it('should handle more than 65535 requests in one connection', function(done) {
should.exist(display);
should.exist(display.screen);
var total = 70000;
var left = total;
var start = Date.now();
function test(err, str) {
if (err)
return done(err);
if (left == 0) {
var end = Date.now();
var dur = end - start;
console.log(total + ' requests finished in ' + dur + ' ms, ' + 1000*total/dur + ' req/sec');
return done();
}
left--;
display.client.GetAtomName(1, test);
}
left++;
test(); // first call starts sequens and not a callback from GetAtomName, thus left++
});
});