Skip to content

Commit

Permalink
Don't increment bytes counter and unref timers if socket is paused
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob McElrath committed Mar 1, 2017
1 parent 94ebd78 commit 1e233b7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,15 +816,15 @@ Socket.prototype._onReceive = function (data) {
var buffer = Buffer.from(data)
var offset = this.bytesRead

this.bytesRead += buffer.length
this._unrefTimer()

if (this.ondata) {
console.error('socket.ondata = func is non-standard, use socket.on(\'data\', func)')
this.ondata(buffer, offset, this.bytesRead)
}
if (!this.push(buffer)) { // if returns false, then apply backpressure
chrome.sockets.tcp.setPaused(this.id, true)
chrome.sockets.tcp.setPaused(this.id, true) // onReceive will be called again with this data
} else {
this.bytesRead += buffer.length
this._unrefTimer()
}
}

Expand Down

0 comments on commit 1e233b7

Please sign in to comment.