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
Add 'drain'-event #1
Comments
i'm not doing any buffering at all so it should be drained every time write is called (i think). @dominictarr said that the |
Oh I just realized the above comment is wrong. sorry, coffee hasnt kicked in yet. lemme research this a bit more |
seems like the only way to do it is by polling http://marcelojabali.blogspot.com/2012/07/websocket-bufferedamount-attribute.html |
That's a pity. Polling will not be near to performant.. Hope there will come an extension to the API anytime... |
It's not as bad as you think, because you only need so start polling when |
The return type of Perhaps after each |
why would they do that? polling an in memory structure isn't that bad... also, you don't need to poll it all the time, only after the buffer has filled. |
Looks like this message was the inspiration for the change. |
hmm, that looks much more serious! it actually closes the connection when the buffer fills! |
We should check |
yes +1 |
I rewrote this module using streams2. Maybe it's easier to implement this now? |
I'm using this patched socketWriteBrowser function to do this: function socketWriteBrowser(chunk, enc, next) {
if (socket.bufferedAmount > 16384) {
setTimeout(function(){
socketWriteBrowser(chunk, enc, next)
}, 10)
return
}
try {
socket.send(chunk)
} catch(err) {
return next(err)
}
next()
} Not sure if this is the best way to go about this but it's been working well so far. With this patch I can upload large (>1gb) files over websockets without chrome eating all memory and cpu. |
@jnordberg I think we should avoid to allocate a closure, it would give us more speed :). Something like: function socketWriteBrowser(chunk, enc, next) {
if (socket.bufferedAmount > 16384) {
return setTimeout(socketWriteBrowser, 10, chunk, enc, next)
}
try {
socket.send(chunk)
} catch(err) {
return next(err)
}
next()
} I'm |
Neat, I didn't know you could pass along arguments to setTimeout. I'll prepare a PR |
Is it possible to add the 'drain'-event?
I looked at the WebSocket specification and there is no such event and I'm not sure if there's a way to do it. But it would be great!
Maybe, you have any idea on how to implement it...
The text was updated successfully, but these errors were encountered: