Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix a bug where multiple messages could arrive in the same chunk

  • Loading branch information...
commit 174a7c0f6701749a5b4d4b8ef298f3190b582a26 1 parent f516483
@substack authored
Showing with 23 additions and 23 deletions.
  1. +1 −1  lib/dnode.js
  2. +1 −1  package.json
  3. +21 −21 test/simple.js
View
2  lib/dnode.js
@@ -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)
}
View
2  package.json
@@ -1,6 +1,6 @@
{
"name" : "dnode",
- "version" : "1.0.2",
+ "version" : "1.0.3",
"description" : "freestyle rpc",
"main" : "./index.js",
"keywords" : [
View
42 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) {
@@ -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);
});
Please sign in to comment.
Something went wrong with that request. Please try again.