diff --git a/lib/x11/xcore.js b/lib/x11/xcore.js index 180b76b..062efe2 100644 --- a/lib/x11/xcore.js +++ b/lib/x11/xcore.js @@ -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); diff --git a/package.json b/package.json index 19c3afb..6761ad3 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/test/sequence-overflow.js b/test/sequence-overflow.js new file mode 100644 index 0000000..20187d4 --- /dev/null +++ b/test/sequence-overflow.js @@ -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++ + }); + +});