Permalink
Browse files

remove non-zero ready condition

  • Loading branch information...
2 parents b551c4a + 439233b commit b67fa4f6a0278bac281d9119e505b292579f0653 @substack committed May 24, 2010
Showing with 236 additions and 28 deletions.
  1. +33 −23 bufferlist/binary.js
  2. +1 −1 tests/all.js
  3. +4 −4 tests/binary_loop.js
  4. +198 −0 tests/binary_rfb.js
  5. BIN tests/rfb-test-data/00-rgba-0-0-720-400.dat
  6. BIN tests/rfb-test-data/01-rgba-80-389-16-7.dat
  7. BIN tests/rfb-test-data/02-rgba-96-390-16-5.dat
  8. BIN tests/rfb-test-data/03-rgba-80-397-32-2.dat
  9. BIN tests/rfb-test-data/04-rgba-96-386-16-10.dat
  10. BIN tests/rfb-test-data/05-rgba-96-397-32-2.dat
  11. BIN tests/rfb-test-data/06-rgba-96-397-32-2.dat
  12. BIN tests/rfb-test-data/07-rgba-112-386-16-10.dat
  13. BIN tests/rfb-test-data/08-rgba-112-397-32-2.dat
  14. BIN tests/rfb-test-data/09-rgba-112-389-32-7.dat
  15. BIN tests/rfb-test-data/10-rgba-112-397-32-2.dat
  16. BIN tests/rfb-test-data/11-rgba-128-386-16-10.dat
  17. BIN tests/rfb-test-data/12-rgba-128-397-32-2.dat
  18. BIN tests/rfb-test-data/13-rgba-144-386-16-10.dat
  19. BIN tests/rfb-test-data/14-rgba-144-397-32-2.dat
  20. BIN tests/rfb-test-data/15-rgba-144-389-16-7.dat
  21. BIN tests/rfb-test-data/16-rgba-144-397-32-2.dat
  22. BIN tests/rfb-test-data/17-rgba-160-393-16-6.dat
  23. BIN tests/rfb-test-data/18-rgba-176-397-16-2.dat
  24. BIN tests/rfb-test-data/19-rgba-160-397-32-2.dat
  25. BIN tests/rfb-test-data/20-rgba-176-386-16-10.dat
  26. BIN tests/rfb-test-data/21-rgba-176-397-32-2.dat
  27. BIN tests/rfb-test-data/22-rgba-176-386-16-10.dat
  28. BIN tests/rfb-test-data/23-rgba-192-389-16-7.dat
  29. BIN tests/rfb-test-data/24-rgba-176-397-32-2.dat
  30. BIN tests/rfb-test-data/25-rgba-192-386-16-2.dat
  31. BIN tests/rfb-test-data/26-rgba-192-389-16-7.dat
  32. BIN tests/rfb-test-data/27-rgba-192-397-32-2.dat
  33. BIN tests/rfb-test-data/28-rgba-208-389-16-7.dat
  34. BIN tests/rfb-test-data/29-rgba-192-390-16-1.dat
  35. BIN tests/rfb-test-data/30-rgba-192-394-16-1.dat
  36. BIN tests/rfb-test-data/31-rgba-192-397-48-2.dat
  37. BIN tests/rfb-test-data/32-rgba-208-397-32-2.dat
  38. BIN tests/rfb-test-data/33-rgba-224-386-16-2.dat
  39. BIN tests/rfb-test-data/34-rgba-224-389-16-7.dat
  40. BIN tests/rfb-test-data/35-rgba-224-397-32-2.dat
  41. BIN tests/rfb-test-data/36-rgba-224-389-16-7.dat
  42. BIN tests/rfb-test-data/37-rgba-240-390-16-1.dat
  43. BIN tests/rfb-test-data/38-rgba-240-394-16-1.dat
  44. BIN tests/rfb-test-data/39-rgba-224-397-32-2.dat
  45. BIN tests/rfb-test-data/40-rgba-240-397-32-2.dat
  46. BIN tests/rfb-test-data/41-rgba-240-389-32-9.dat
  47. BIN tests/rfb-test-data/42-rgba-256-398-16-1.dat
  48. BIN tests/rfb-test-data/43-rgba-256-389-16-7.dat
  49. BIN tests/rfb-test-data/44-rgba-256-397-32-2.dat
  50. BIN tests/rfb-test-data/45-rgba-256-389-32-7.dat
  51. BIN tests/rfb-test-data/46-rgba-256-397-32-2.dat
  52. BIN tests/rfb-test-data/47-rgba-272-389-16-10.dat
  53. BIN tests/rfb-test-data/48-rgba-288-397-16-2.dat
  54. BIN tests/rfb-test-data/49-rgba-288-389-16-7.dat
  55. BIN tests/rfb-test-data/50-rgba-288-397-32-2.dat
  56. BIN tests/rfb-test-data/51-rgba-288-389-16-7.dat
  57. BIN tests/rfb-test-data/52-rgba-288-397-32-2.dat
  58. BIN tests/rfb-test-data/53-rgba-304-389-16-7.dat
  59. BIN tests/rfb-test-data/54-rgba-304-397-32-2.dat
  60. BIN tests/rfb-test-data/55-rgba-304-389-32-7.dat
  61. BIN tests/rfb-test-data/56-rgba-304-397-32-2.dat
  62. BIN tests/rfb-test-data/57-rgba-320-386-16-2.dat
  63. BIN tests/rfb-test-data/58-rgba-320-389-16-7.dat
  64. BIN tests/rfb-test-data/59-rgba-320-397-32-2.dat
  65. BIN tests/rfb-test-data/60-rgba-320-389-32-7.dat
  66. BIN tests/rfb-test-data/61-rgba-320-397-32-2.dat
  67. BIN tests/rfb-test-data/62-rgba-336-389-16-10.dat
  68. BIN tests/rfb-test-data/63-rgba-352-397-16-2.dat
  69. BIN tests/rfb-test-data/64-rgba-336-397-48-2.dat
  70. BIN tests/rfb-test-data/65-rgba-352-389-16-7.dat
  71. BIN tests/rfb-test-data/66-rgba-352-397-32-2.dat
  72. BIN tests/rfb-test-data/67-rgba-368-389-16-7.dat
  73. BIN tests/rfb-test-data/68-rgba-368-397-32-2.dat
  74. BIN tests/rfb-test-data/69-rgba-368-386-16-2.dat
  75. BIN tests/rfb-test-data/70-rgba-368-389-16-7.dat
  76. BIN tests/rfb-test-data/71-rgba-368-397-32-2.dat
  77. BIN tests/rfb-test-data/72-rgba-384-386-16-10.dat
  78. BIN tests/rfb-test-data/73-rgba-384-397-32-2.dat
  79. BIN tests/rfb-test-data/74-rgba-384-386-16-10.dat
  80. BIN tests/rfb-test-data/75-rgba-400-389-16-1.dat
  81. BIN tests/rfb-test-data/76-rgba-400-394-16-2.dat
  82. BIN tests/rfb-test-data/77-rgba-384-397-32-2.dat
  83. BIN tests/rfb-test-data/78-rgba-400-386-16-10.dat
  84. BIN tests/rfb-test-data/79-rgba-400-397-32-2.dat
  85. BIN tests/rfb-test-data/80-rgba-400-389-32-7.dat
  86. BIN tests/rfb-test-data/81-rgba-416-396-16-3.dat
  87. BIN tests/rfb-test-data/82-rgba-400-397-16-1.dat
  88. BIN tests/rfb-test-data/83-rgba-416-394-16-2.dat
  89. BIN tests/rfb-test-data/84-rgba-416-397-32-2.dat
  90. BIN tests/rfb-test-data/85-rgba-80-5-64-7.dat
  91. BIN tests/rfb-test-data/86-rgba-16-18-64-10.dat
View
@@ -45,7 +45,8 @@ function Binary(buffer) {
action : function () {
g.call(this, this.vars);
f.call(binary, g);
- }
+ },
+ type : 'forever'
};
this.pushAction(action);
setTimeout(function () {
@@ -56,23 +57,37 @@ function Binary(buffer) {
}
this.f = function (x) {
- sys.log(x);
+ this.pushAction({
+ ready : true,
+ action : function () {
+ sys.log(x);
+ }
+ });
+ return this;
+ }
+
+ this.dc = function() {
+ this.pushAction({
+ ready : true,
+ action : function () {
+ sys.p(contexts);
+ }
+ });
return this;
}
// Repeat some action n times
this.repeat = function (n, f) {
var n = typeof(n) == 'string' ? this.vars[n] : n;
- for (var i = 0; i < n; i++) {
- this.pushAction({
- ready : true,
- action : function () {
- // last arg is i so vars is in the usual place
- this.pushContext();
- f.call(this, this.vars, i);
- this.lazyPopContext();
- }
- });
+ for (var i=0; i<n; i++) {
+ (function (j) {
+ this.pushAction({
+ ready : true,
+ action : function () {
+ f.call(this, this.vars, j);
+ }
+ });
+ }).call(this, i);
}
return this;
}
@@ -180,16 +195,10 @@ function Binary(buffer) {
this.gets = function (opts) {
if (typeof(opts.length) == 'string') {
- var s = opts.length;
- opts.length = function (vars) { return vars[s] };
+ var length = function (vars) { return vars[opts.length] };
}
else if (typeof(opts.length) == 'number') {
- var s = opts.length;
- opts.length = function (vars) { return s };
- }
-
- function size () {
- return opts.length.call(binary,binary.vars) * opts.bytes;
+ var length = function (vars) { return opts.length };
}
var into_t = typeof(opts.into);
@@ -200,11 +209,11 @@ function Binary(buffer) {
this.pushAction({
ready : function () {
- var s = size();
- return s && buffer.length - offset >= s;
+ var s = length.call(binary,binary.vars) * opts.bytes;
+ return buffer.length - offset >= s;
},
action : function () {
- var s = size();
+ var s = length.call(binary,binary.vars) * opts.bytes;
var data = buffer.join(offset, offset + s);
offset += s;
@@ -306,6 +315,7 @@ function Binary(buffer) {
var binary = this;
function process () {
+ sys.log(buffer.length);
var action = binary.nextAction()
if (!action) return;
View
@@ -8,7 +8,7 @@ var scriptName = path.basename(__filename);
fs.readdir(__dirname, function (err, files) {
var tests = files.filter(function (file) {
- return file.match(/\.js$/) && file != scriptName;
+ return file.match(/\.js$/) && file != scriptName && file != 'binary_rfb.js'
});
var failed = 0;
View
@@ -29,9 +29,9 @@ Binary(new BufferList)
})
.tap(function (vars) {
expectedTrickyList = [
- [1,1],[1,2],[1,3],[1,4],
- [2,1],[2,2],[2,3],[2,4],
- [3,1],[3,2],[3,3],[3,4]
+ [0,0],[0,1],[0,2],[0,3],
+ [1,0],[1,1],[1,2],[1,3],
+ [2,0],[2,1],[2,2],[2,3]
];
for (var i = 0; i < trickyList.length; i++) {
assert.equal(
@@ -64,7 +64,7 @@ Binary(new BufferList)
setTimeout(function () {
assert.equal(
- c, 10000, 'c != 100, c == ' + c + ' in terminated forever check'
+ c, 10000, 'c != 10000, c == ' + c + ' in terminated forever check'
);
}, 1000);
View
@@ -0,0 +1,198 @@
+#!/usr/bin/env node
+// Starts a rfb server that listens on port 59000 and serves rectangles from
+// ./tests/rfb-test-data directory
+
+var sys = require('sys');
+var net = require('net');
+var fs = require('fs');
+var path = require('path');
+
+function Word8(x) {
+ return String.fromCharCode(x);
+}
+
+function Word16be(x) {
+ return String.fromCharCode((x>>8)&0xFF) + String.fromCharCode(x&0xFF);
+}
+
+function Word32be(x) {
+ return String.fromCharCode((x>>24)&0xFF) + String.fromCharCode((x>>16)&0xFF) +
+ String.fromCharCode((x>>8)&0xFF) + String.fromCharCode(x&0xFF);
+}
+
+var S_EXPECT_RFB = 0;
+var S_EXPECT_SECNUM = 1;
+var S_EXPECT_SHARED = 2;
+var S_EXPECT_FB_UPDATE = 3;
+
+var RFBServer = net.createServer(function (stream) {
+ var state = S_EXPECT_RFB;
+ stream.setEncoding('binary');
+ stream.addListener('connect', function () {
+ sys.log('client connected, sending RFB version to client');
+ stream.write('RFB 003.008\n');
+ });
+ stream.addListener('data', function (data) {
+ if (state == S_EXPECT_RFB) {
+ if (!/RFB 003\.008\n/.test(data)) {
+ sys.log('client sent wrong RFB version string: ' + data);
+ stream.end();
+ return;
+ }
+ sys.log('got RFB version from client, writing secLen 1 and secTypes 1');
+ stream.write('\x01', 'binary'); // secLen of 1
+ stream.write('\x01', 'binary'); // secTypes 1
+ state = S_EXPECT_SECNUM;
+ }
+ else if (state == S_EXPECT_SECNUM) {
+ stream.write('\x00\x00\x00\x00'); // secRes
+ state = S_EXPECT_SHARED;
+ }
+ else if (state == S_EXPECT_SHARED) {
+ stream.write(Word16be(720), 'binary');
+ stream.write(Word16be(400), 'binary');
+ stream.write(Word8(32), 'binary');
+ stream.write(Word8(1), 'binary');
+ stream.write(Word8(2), 'binary');
+ stream.write(Word8(3), 'binary');
+ stream.write(Word16be(4), 'binary');
+ stream.write(Word16be(5), 'binary');
+ stream.write(Word16be(6), 'binary');
+ stream.write(Word8(7), 'binary');
+ stream.write(Word8(8), 'binary');
+ stream.write(Word8(9), 'binary');
+
+ stream.write(Word8(10), 'binary'); // padding 3 bytes
+ stream.write(Word8(11), 'binary');
+ stream.write(Word8(12), 'binary');
+
+ stream.write(Word32be(4), 'binary'); // nameLength
+ stream.write("test");
+
+ state = S_EXPECT_FB_UPDATE;
+ }
+ else if (state = S_EXPECT_FB_UPDATE) {
+ // here the fun begins, send the updates from rfb-test-data directory
+ //
+
+ var SEND_TYPE = 'one'; // send one rect at a time, use 'all' to send all
+
+ fs.readdir(__dirname + '/rfb-test-data', function (err, files) {
+ function rectDim(fileName) {
+ var m = fileName.match(/^\d+-rgba-(\d+)-(\d+)-(\d+)-(\d+).dat$/);
+ var dim = [m[1], m[2], m[3], m[4]].map(function (n) {
+ return parseInt(n, 10);
+ });
+ return { x: dim[0], y: dim[1], w: dim[2], h: dim[3] }
+ }
+
+ function sendFile(fileName) {
+ var dim = rectDim(fileName);
+ var data = fs.readFileSync(__dirname + '/rfb-test-data/' + fileName, 'binary');
+
+ sys.log('sending ' + rgbaFiles[i]);
+
+ /* writing data individually makes node-rfb go nuts */
+
+ stream.write('\x00', 'binary'); // serverMsgTypes.fbUpdate
+ stream.write('\x00', 'binary'); // skip 1 byte
+ stream.write(Word16be(1), 'binary'); // nRects
+ stream.write(Word16be(dim.x), 'binary'); // x
+ stream.write(Word16be(dim.y), 'binary'); // y
+ stream.write(Word16be(dim.w), 'binary'); // w
+ stream.write(Word16be(dim.h), 'binary'); // h
+ stream.write(Word32be(0), 'binary'); // encodingType
+ stream.write(data, 'binary');
+
+
+
+ /*
+
+ var buf = [];
+
+ buf.push('\x00'); // serverMsgTypes.fbUpdate
+ buf.push('\x00'); // skip 1 byte
+ buf.push(Word16be(1)); // nRects
+ buf.push(Word16be(dim.x)); // x
+ buf.push(Word16be(dim.y)); // y
+ buf.push(Word16be(dim.w)); // w
+ buf.push(Word16be(dim.h)); // h
+ buf.push(Word32be(0)); // encodingType
+ buf.push(data);
+ sys.log(data.length);
+
+ var toSend = buf.join('');
+ stream.write(toSend, 'binary');
+
+ */
+ }
+
+ function sendAll(files) {
+
+ /* writing data individually makes node-rfb go nuts
+
+ stream.write('\x00', 'binary'); // serverMsgTypes.fbUpdate
+ stream.write('\x00', 'binary'); // skip 1 byte
+ stream.write(Word16be(files.length), 'binary'); // nRects
+ for (var i = 0; i<files.length; i++) {
+ var fileName = files[i];
+ var dim = rectDim(fileName);
+ var data = fs.readFileSync(__dirname + '/rfb-test-data/' + fileName, 'binary');
+ stream.write(Word16be(dim.x), 'binary'); // x
+ stream.write(Word16be(dim.y), 'binary'); // y
+ stream.write(Word16be(dim.w), 'binary'); // w
+ stream.write(Word16be(dim.h), 'binary'); // h
+ stream.write(Word32be(0), 'binary'); // encodingType
+ stream.write(data, 'binary');
+ }
+
+ */
+
+ var buf = [];
+
+ buf.push('\x00'); // serverMsgTypes.fbUpdate
+ buf.push('\x00'); // skip 1 byte
+ buf.push(Word16be(files.length)); // nRects
+ for (var i = 0; i<files.length; i++) {
+ var fileName = files[i];
+ var dim = rectDim(fileName);
+ var data = fs.readFileSync(__dirname + '/rfb-test-data/' + fileName, 'binary');
+ buf.push(Word16be(dim.x)); // x
+ buf.push(Word16be(dim.y)); // y
+ buf.push(Word16be(dim.w)); // w
+ buf.push(Word16be(dim.h)); // h
+ buf.push(Word32be(0)); // encodingType
+ buf.push(data);
+ }
+
+ var toSend = buf.join('');
+ stream.write(toSend, 'binary');
+ }
+
+ var rgbaFiles = files.filter(function (file) {
+ return file.match(/^\d+-rgba-\d+-\d+-\d+-\d+\.dat$/)
+ }).sort();
+
+ if (SEND_TYPE == 'one') {
+ //for (var i=0; i<rgbaFiles.length; i++) {
+ for (var i=0; i<1; i++) { // enough to make node-rfb go nuts
+ sendFile(rgbaFiles[i]);
+ }
+ }
+ else if (SEND_TYPE == 'all') {
+ sendAll(rgbaFiles);
+ }
+ else {
+ sys.log('unknown SEND_TYPE');
+ process.exit(1);
+ }
+ });
+ }
+ });
+ stream.addListener('end', function () {
+ sys.log('client disconnected');
+ });
+}).listen(59000);
+
+sys.log('rfb server on port 59000');
+
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit b67fa4f

Please sign in to comment.