Permalink
Browse files

Merge branch 'master' of github.com:nodejitsu/nssocket

  • Loading branch information...
2 parents 8e9f0ad + 2ffb593 commit 7e59221f5b8a86dd8f453a2c81ee8cdadfe37315 hij1nx committed Jul 29, 2011
Showing with 11 additions and 15 deletions.
  1. +5 −6 lib/nssocket.js
  2. +6 −9 test/tcp-test.js
View
11 lib/nssocket.js
@@ -76,18 +76,18 @@ var NsSocket = exports.NsSocket = function (socket, options) {
}
// make sure we listen to the underlying socket
- socket.on(startName, this.emitStart);
- socket.on('data', this.emitData);
- socket.on('close', this.emitClose);
+ socket.on(startName, this.emitStart.bind(this));
+ socket.on('data', this.emitData.bind(this));
+ socket.on('close', this.emitClose.bind(this));
if (socket.socket) {
// otherwise we get a error passed from net.js
// they need to backport the fix from v5 to v4
socket.socket.on('error', function () {});
}
- socket.on('error', this.emitError);
- socket.on('timeout', this.emitIdle);
+ socket.on('error', this.emitError.bind(this));
+ socket.on('timeout', this.emitIdle.bind(this));
};
@@ -111,7 +111,6 @@ NsSocket.prototype.emitStart = function emitStart() {
// We assume messages arrive in order.
//
NsSocket.prototype.emitData = function emitData(message) {
-
this.emit('data', message.toString());
// relative constants
View
15 test/tcp-test.js
@@ -59,8 +59,7 @@ vows.describe('nssocket').addBatch({
socket.on('data.}here.}is', this.callback.bind(null, null));
s.write('here.}is.}something.}');
},
- "we should see it show up with the delimiter" : function (ign, event, datas) {
- assert.isString(event);
+ "we should see it show up with the delimiter" : function (ign, datas) {
assert.isArray(datas);
assert.length(datas, 3);
assert.isString(datas[0]);
@@ -69,13 +68,12 @@ vows.describe('nssocket').addBatch({
assert.equal(datas[1], 'is');
},
"and if we were to set it to idle" : {
- topic : function (_,_,socket,s) {
+ topic : function (_,socket,s) {
socket.once('idle', this.callback.bind(null,null,socket,s));
socket.setIdle(100);
},
- "we should see the socket emit `idle` event" : function (ign, socket, s, event) {
- assert.isString(event);
- assert.equal(event, 'idle');
+ "we should see the socket emit `idle` event" : function (ign, socket, s) {
+ assert.isNull(ign);
},
"If we were to send a message on the socket" : {
topic : function (socket, s) {
@@ -97,9 +95,8 @@ vows.describe('nssocket').addBatch({
socket.on('close', this.callback.bind(null,null,socket,s));
s.end();
},
- "we should see it close" : function (ign, socket, s, event) {
- assert.isString(event);
- assert.equal(event, 'close');
+ "we should see it close without errors" : function (ign, socket, s, err) {
+ assert.isUndefined(err);
}
}
}

0 comments on commit 7e59221

Please sign in to comment.