Skip to content
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

Buffering incomplete data #96

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/stomp-node.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/stomp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/stomp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/stomp-node.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# or Web sockets.

###
Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0
Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ |
Apache License V2.0

Copyright (C) 2013 [Jeff Mesnil](http://jmesnil.net/)
###
Expand Down Expand Up @@ -36,11 +37,18 @@ wrapTCP = (port, host) ->
socket = net.connect port, host, (e) -> ws.onopen()
socket.on 'error', (e) -> ws.onclose?(e)
socket.on 'close', (e) -> ws.onclose?(e)
buffer = new Buffer(0)
socket.on 'data', (data) ->
data = Buffer.concat([buffer, data])
if ('\n' != data.slice(-1).toString())
buffer = data
return

event = {
'data': data.toString()
}
ws.onmessage(event)
buffer = new Buffer(0)

return ws

Expand Down
12 changes: 10 additions & 2 deletions src/stomp-node.orig.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@ var wrapTCP = function(port, host) {
ws.onclose();
}
});
var buffer = new Buffer(0);
socket.on('data', function(data) {
data = Buffer.concat([buffer, data]);
if ('\n' != data.slice(-1)) {
buffer = data;
return;
}

// wrap the data in an event object
var event = {
'data': data.toString()
};
ws.onmessage(event);
buffer = new Buffer(0);
});

return ws;
};

Expand All @@ -56,7 +64,7 @@ var wrapWS = function(url) {
connection.close();
}
};

var socket = new WebSocketClient();
socket.on('connect', function(conn) {
connection = conn;
Expand Down