You might want to try "objectMode" on the Transform stream to prevent the
"frames being glued together" behavior you are experiencing.

On Sun, Mar 24, 2013 at 6:42 AM, Bodo Kaiser <bodo.kai...@enabre.com> wrote:

> Hello,
>
> I am working on another WebSocket RFC6455 implementation and am currently
> trying to handle following issue:
> The "data" events of the socket instance I receive from the http server's
> "upgrade" event does (in specific use-cases) provide chunked data instead
> of the direct frames.
>
> These use cases are:
>
> 1. When the frame exceeds the size of the highWaterMark of 16kb (causes
> the frame to get splitted)
> 2. When the incoming frames have low latency to each other (e.g. on for
> loops) they are glued together
>
> To get frame chunks out of the above use-cases I wrote a TransformStream.
> The thing about the below implementation is that it feels wrong.
> Are my feelings correct? Is there an alternative?
>
>
> function WebSocketStream(options) {
>     stream.Transform.call(this, options);
>
>     this.cache = null;
>     this.caching = false;
> }
>
> util.inherits(WebSocketStream, stream.Transform);
>
> WebSocketStream.prototype._transform = function(chunk, encoding, done) {
>     // if we are package was incomplete concat the chunk with cache
>     if (this.caching) {
>         chunk = Buffer.concat([this.cache, chunk]);
>         this.cache = null;
>
>         this.caching = false;
>     }
>
>     // detect if frame is incomplete, set flags and return
>
>     if (isSplittedFrame(chunk)) {
>         this.cache = chunk;
>         this.caching = true;
>
>         return done();
>     }
>
>     while (chunk) {
>         this.push(frameOnly(chunk));
>         chunk = remnantOnly(chunk);
>     }
>
>     done();
> };
>
> module.exports = WebSocketStream;
>
> Best regards,
> Bodo Kaiser
>
>  --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nodejs+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to