Skip to content

Commit

Permalink
fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
masuidrive committed Dec 3, 2011
1 parent d60d955 commit e9c8b4f
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions lib/websocket-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,25 +413,27 @@ WebSocket.prototype._read_callback = function(e) {
Ti.Stream.read(self._socket, self._socketReadBuffer, function(e) { self._read_callback(e); });
};

if ("undefined" === typeof e || e.bytesProcessed === 0) {
return nextTick();
}
if('undefined' !== typeof e) {
if (0 === e.bytesProcessed) {
return nextTick();
}

if (e.bytesProcessed === -1) { // EOF
this._socket_close();
return undefined;
}
if(-1 === e.bytesProcessed) { // EOF
this._socket_close();
return undefined;
}

if('undefined' === typeof this.buffer) {
this.buffer = this._socketReadBuffer.clone();
this.bufferSize = e.bytesProcessed;
}
else {
this.buffer.copy(this._socketReadBuffer, this.bufferSize, 0, e.bytesProcessed);
this.bufferSize += e.bytesProcessed;
this._socketReadBuffer.clear();
if('undefined' === typeof this.buffer) {
this.buffer = this._socketReadBuffer.clone();
this.bufferSize = e.bytesProcessed;
}
else {
this.buffer.copy(this._socketReadBuffer, this.bufferSize, 0, e.bytesProcessed);
this.bufferSize += e.bytesProcessed;
this._socketReadBuffer.clear();
}
}

var frame = parse_frame(this.buffer, this.bufferSize);
if('undefined' === typeof frame) {
return nextTick();
Expand Down Expand Up @@ -490,7 +492,6 @@ WebSocket.prototype._read_callback = function(e) {
this._read_callback();
}
};

WebSocket.prototype._error = function(code, reason) {
if(this.buffer) {
this.buffer.clear();
Expand Down

0 comments on commit e9c8b4f

Please sign in to comment.