Skip to content

Commit

Permalink
fix a bug where multiple messages could arrive in the same chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Dec 17, 2012
1 parent f516483 commit 174a7c0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/dnode.js
Expand Up @@ -122,9 +122,9 @@ dnode.prototype.write = function (buf) {
if (buf.charCodeAt(i) === 0x0a) {
try { row = json.parse(self._line) }
catch (err) { return self.end() }
self._line = '';

self.handle(row);
self._line = '';
}
else self._line += buf.charAt(i)
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name" : "dnode",
"version" : "1.0.2",
"version" : "1.0.3",
"description" : "freestyle rpc",
"main" : "./index.js",
"keywords" : [
Expand Down
42 changes: 21 additions & 21 deletions test/simple.js
@@ -1,9 +1,8 @@
var dnode = require('../');
var test = require('tap').test;
var test = require('tape');

test('simple', function (t) {
t.plan(7);
var port = Math.floor(Math.random() * 40000 + 10000);
test('simple server and client', function (t) {
t.plan(5);

var server = dnode({
timesTen : function (n,reply) {
Expand All @@ -15,25 +14,26 @@ test('simple', function (t) {
t.equal(n, 5);
cb(n * 10);
},
}).listen(port.toString()); // test for stringified ports too why not
});

server.on('listening', function () {
dnode.connect(port, function (remote, conn) {
t.ok(conn.id);
t.equal(conn.stream.remoteAddress, '127.0.0.1');

remote.moo(function (x) {
t.equal(x, 100, 'remote moo == 100');
});
remote.sTimesTen(5, function (m) {
t.equal(m, 50, '5 * 10 == 50');
remote.timesTen(m, function (n) {
t.equal(n, 500, '50 * 10 == 500');
conn.end();
server.close();
t.end();
});
var client = dnode();
client.on('remote', function (remote) {
remote.moo(function (x) {
t.equal(x, 100, 'remote moo == 100');
});
remote.sTimesTen(5, function (m) {
t.equal(m, 50, '5 * 10 == 50');
remote.timesTen(m, function (n) {
t.equal(n, 500, '50 * 10 == 500');
});
});
});

server.on('end', function () {
console.log('server END');
});
client.on('end', function () {
console.log('client END');
});
server.pipe(client).pipe(server);
});

0 comments on commit 174a7c0

Please sign in to comment.