-
Notifications
You must be signed in to change notification settings - Fork 353
Ws drain fix #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ws drain fix #140
Changes from 5 commits
e358f0d
bf13803
8ea4bb9
28766db
c16137a
d5fa387
dab01cf
05a0647
7d941af
e652ead
0874020
aa5dec5
74094e1
71ed033
d6ba4f8
f3710ff
1f6ee88
fdb95d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ var global = util.global(); | |
|
|
||
| function WS(opts){ | ||
| Transport.call(this, opts); | ||
| this.bufferedAmountId; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for this |
||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -82,11 +83,32 @@ WS.prototype.doOpen = function(){ | |
| */ | ||
|
|
||
| WS.prototype.write = function(packets){ | ||
| for (var i = 0, l = packets.length; i < l; i++) { | ||
| this.socket.send(parser.encodePacket(packets[i])); | ||
| var self = this; | ||
| // encodePayload instead of encodePacket | ||
| this.writable = false; | ||
| this.socket.send(parser.encodePayload(packets)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (we should add a comment for that) |
||
| // check periodically if we're done sending | ||
| if ('bufferedAmount' in this.socket) { | ||
| this.bufferedAmountId = this.setInterval(function() { | ||
| if (this.socket.bufferedAmount == 0) { | ||
| clearInterval(self.bufferedAmountId); | ||
| this.writable = true; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| this.emit('drain'); | ||
| } | ||
| }, 50); | ||
| } else { | ||
| // fake drain | ||
| this.writable = true; | ||
| this.emit('drain'); | ||
| } | ||
| }; | ||
|
|
||
| WS.prototype.intervalCleanup = function(){ | ||
| if (this.bufferedAmountId) { | ||
| clearInterval(this.bufferedAmountId); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for |
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Closes socket. | ||
| * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This belongs in the WS
onClose