Compare commits

..

7 Commits
1.2.0 ... 1.2.1

Author SHA1 Message Date
Guillermo Rauch
24d06d76dd Release 1.2.1 2014-11-21 04:59:14 +01:00
Guillermo Rauch
4e4bbf918e fix protocol violations and improve error handling (fixes #1880) 2014-11-21 04:16:37 +01:00
Guillermo Rauch
b49f5c82f2 syntax 2014-11-21 04:15:42 +01:00
Guillermo Rauch
5bd67195de Merge branch 'master' of github.com:Automattic/socket.io 2014-11-21 02:57:35 +01:00
Guillermo Rauch
73fe547956 package: bump engine.io for websocket leak fix 2014-11-21 02:56:28 +01:00
Guillermo Rauch
973e6cc982 Merge pull request #1813 from ogwiz2/patch-1
Made comments more consistent
2014-11-12 10:04:09 +01:00
Alex Jeng
136fe960b7 Made comments more consistent 2014-10-05 22:10:13 -07:00
5 changed files with 83 additions and 7 deletions

View File

@@ -1,4 +1,11 @@
1.2.1 / 2014-11-21
==================
* fix protocol violations and improve error handling (GH-1880)
* package: bump `engine.io` for websocket leak fix [3rd-Eden]
* style tweaks
1.2.0 / 2014-10-27
==================

View File

@@ -42,9 +42,12 @@ function Client(server, conn){
Client.prototype.setup = function(){
this.onclose = this.onclose.bind(this);
this.ondata = this.ondata.bind(this);
this.onerror = this.onerror.bind(this);
this.ondecoded = this.ondecoded.bind(this);
this.decoder.on('decoded', this.ondecoded);
this.conn.on('data', this.ondata);
this.conn.on('error', this.onerror);
this.conn.on('close', this.onclose);
};
@@ -167,7 +170,12 @@ Client.prototype.packet = function(packet, preEncoded, volatile){
*/
Client.prototype.ondata = function(data){
this.decoder.add(data);
// try/catch is needed for protocol violations (GH-1880)
try {
this.decoder.add(data);
} catch(e) {
this.onerror(e);
}
};
/**
@@ -189,6 +197,20 @@ Client.prototype.ondecoded = function(packet) {
}
};
/**
* Handles an error.
*
* @param {Objcet} error object
* @api private
*/
Client.prototype.onerror = function(err){
this.sockets.forEach(function(socket){
socket.onerror(err);
});
this.onclose('client error');
};
/**
* Called upon transport close.
*
@@ -219,6 +241,7 @@ Client.prototype.onclose = function(reason){
Client.prototype.destroy = function(){
this.conn.removeListener('data', this.ondata);
this.conn.removeListener('error', this.onerror);
this.conn.removeListener('close', this.onclose);
this.decoder.removeListener('decoded', this.ondecoded);
};

View File

@@ -380,10 +380,21 @@ Socket.prototype.ondisconnect = function(){
this.onclose('client namespace disconnect');
};
/**
* Handles a client error.
*
* @api private
*/
Socket.prototype.onerror = function(err){
this.emit('error', err);
};
/**
* Called upon closing. Called by `Client`.
*
* @param {String} reason
* @param {Error} optional error object
* @api private
*/

View File

@@ -1,6 +1,6 @@
{
"name": "socket.io",
"version": "1.2.0",
"version": "1.2.1",
"description": "node.js realtime framework server",
"keywords": [
"realtime",
@@ -19,9 +19,9 @@
"test": "make test"
},
"dependencies": {
"engine.io": "1.4.2",
"engine.io": "1.4.3",
"socket.io-parser": "2.2.2",
"socket.io-client": "1.2.0",
"socket.io-client": "1.2.1",
"socket.io-adapter": "0.3.1",
"has-binary-data": "0.1.3",
"debug": "0.7.4"

View File

@@ -7,7 +7,7 @@ var ioc = require('socket.io-client');
var request = require('supertest');
var expect = require('expect.js');
// creates a socket.io client for the given server
// Creates a socket.io client for the given server
function client(srv, nsp, opts){
if ('object' == typeof nsp) {
opts = nsp;
@@ -273,8 +273,9 @@ describe('socket.io', function(){
it('should allow request when origin defined as function and same is supplied', function(done) {
var sockets = io({ origins: function(origin,callback){
if(origin == 'http://foo.example')
if (origin == 'http://foo.example') {
return callback(null, true);
}
return callback(null, false);
} }).listen('54016');
request.get('http://localhost:54016/socket.io/default/')
@@ -288,8 +289,9 @@ describe('socket.io', function(){
it('should allow request when origin defined as function and different is supplied', function(done) {
var sockets = io({ origins: function(origin,callback){
if(origin == 'http://foo.example')
if (origin == 'http://foo.example') {
return callback(null, true);
}
return callback(null, false);
} }).listen('54017');
request.get('http://localhost:54017/socket.io/default/')
@@ -637,6 +639,39 @@ describe('socket.io', function(){
});
});
it('should error with null messages', function(done){
var srv = http();
var sio = io(srv);
srv.listen(function(){
var socket = client(srv);
sio.on('connection', function(s){
s.on('message', function(a){
expect(a).to.be(null);
done();
});
socket.send(null);
});
});
});
it('should handle transport null messages', function(done){
var srv = http();
var sio = io(srv);
srv.listen(function(){
var socket = client(srv);
sio.on('connection', function(s){
s.on('error', function(err){
expect(err).to.be.an(Error);
s.on('disconnect', function(reason){
expect(reason).to.be('client error');
done();
});
});
s.client.ondata(null);
});
});
});
it('should emit events', function(done){
var srv = http();
var sio = io(srv);