Skip to content

Commit

Permalink
Merge remote-tracking branch 'rechardchen/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokaiser committed Oct 4, 2011
2 parents 7f74b24 + ed8e18d commit f85ac98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/ws/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,6 @@ Parser.prototype.write = function(data) {
var pkt, msg;

debug('parse.write', data.inspect());

for (var i = 0, len = data.length; i < len; i++) {
if (this.order == 0) {
if ((data[i] & 0x08) == 0x08) {
Expand Down Expand Up @@ -525,7 +524,9 @@ Parser.prototype.write = function(data) {
} else if (data[i] === 0xFF && this.frameData.length == 0) {
this.closing = true;
} else {
if (i == 0) {
if (! this.flag) { //only for draft10
this.flag = 1;
this.startPos = i;
continue;
}

Expand All @@ -534,15 +535,15 @@ Parser.prototype.write = function(data) {
this.length = data[i] & 0x7f;

if (this.length < 126) {
this.mask = data.slice(2, 6);
i = 6; // skip the mask bytes
this.mask = data.slice(this.startPos+2, this.startPos+6);
i = this.startPos+6; // skip the mask bytes
}

if (this.length == 126) {
this.mask = data.slice(4, 8);
i = 8; // skip the mask bytes
this.mask = data.slice(this.startPos+4, this.startPos+8);
i = this.startPos+8; // skip the mask bytes

var lengthBytes = data.slice(2, 4);
var lengthBytes = data.slice(this.startPos+2, this.startPos+4);
this.length = lengthBytes[1] + (lengthBytes[0] << 8);
}
}
Expand All @@ -560,7 +561,7 @@ Parser.prototype.write = function(data) {
this.mask = null;
this.order = 0;
this.frameData = [];

this.flag = 0;
this.emit('message', pkt.toString('utf8', 0, pkt.length));
}
}
Expand Down
2 changes: 2 additions & 0 deletions problems.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. if you send message too often(e.g send per 10ms), than unexpected thing will happen.Not sure whether it will happen if too many clients connected to the server (fixed 2011/9/25)
2. cannot handle frame fragmentation

0 comments on commit f85ac98

Please sign in to comment.