From 382babb072df7e4d02126c1b3802dcfe779388ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=91=AB=28=E5=AA=92=E4=BD=93=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=BA=BF=2E202368=29?= Date: Tue, 23 Dec 2014 18:08:22 +0800 Subject: [PATCH 1/4] Buffering incomplete data --- lib/stomp-node.js | 10 ++++++++-- lib/stomp.js | 2 +- lib/stomp.min.js | 2 +- src/stomp-node.coffee | 6 ++++++ src/stomp-node.orig.js | 12 ++++++++++-- 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/stomp-node.js b/lib/stomp-node.js index 68660ee..ee60f97 100644 --- a/lib/stomp-node.js +++ b/lib/stomp-node.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.7.1 +// Generated by CoffeeScript 1.8.0 /* Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0 @@ -22,7 +22,7 @@ }; wrapTCP = function(port, host) { - var socket, ws; + var buffer, socket, ws; socket = null; ws = { url: 'tcp:// ' + host + ':' + port, @@ -42,8 +42,14 @@ socket.on('close', function(e) { return typeof ws.onclose === "function" ? ws.onclose(e) : void 0; }); + buffer = new Buffer(0); socket.on('data', function(data) { var event; + data = Buffer.concat([buffer, data]); + if ('\n' !== data.slice(-1)) { + buffer = data; + return; + } event = { 'data': data.toString() }; diff --git a/lib/stomp.js b/lib/stomp.js index 9c30356..9a552a3 100644 --- a/lib/stomp.js +++ b/lib/stomp.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.7.1 +// Generated by CoffeeScript 1.8.0 /* Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0 diff --git a/lib/stomp.min.js b/lib/stomp.min.js index dd0b1fa..8e43654 100644 --- a/lib/stomp.min.js +++ b/lib/stomp.min.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 1.7.1 +// Generated by CoffeeScript 1.8.0 /* Stomp Over WebSocket http://www.jmesnil.net/stomp-websocket/doc/ | Apache License V2.0 diff --git a/src/stomp-node.coffee b/src/stomp-node.coffee index 1ba0862..df2c592 100644 --- a/src/stomp-node.coffee +++ b/src/stomp-node.coffee @@ -36,7 +36,13 @@ 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)) + buffer = data + return; + event = { 'data': data.toString() } diff --git a/src/stomp-node.orig.js b/src/stomp-node.orig.js index ce68ee3..5684201 100644 --- a/src/stomp-node.orig.js +++ b/src/stomp-node.orig.js @@ -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; }; @@ -56,7 +64,7 @@ var wrapWS = function(url) { connection.close(); } }; - + var socket = new WebSocketClient(); socket.on('connect', function(conn) { connection = conn; From 0b0ce8a2e90b768bc010177b7ae456c3fe513e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=91=AB=28=E5=AA=92=E4=BD=93=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=BA=BF=2E202368=29?= Date: Tue, 23 Dec 2014 19:53:40 +0800 Subject: [PATCH 2/4] Typo --- lib/stomp-node.js | 3 ++- src/stomp-node.coffee | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/stomp-node.js b/lib/stomp-node.js index ee60f97..4e9e6a2 100644 --- a/lib/stomp-node.js +++ b/lib/stomp-node.js @@ -53,7 +53,8 @@ event = { 'data': data.toString() }; - return ws.onmessage(event); + ws.onmessage(event); + return buffer = new Buffer(0); }); return ws; }; diff --git a/src/stomp-node.coffee b/src/stomp-node.coffee index df2c592..0370e24 100644 --- a/src/stomp-node.coffee +++ b/src/stomp-node.coffee @@ -47,6 +47,7 @@ wrapTCP = (port, host) -> 'data': data.toString() } ws.onmessage(event) + buffer = new Buffer(0) return ws From a15674f9e200d6be6f5b733b39cff670226453e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=91=AB=28=E5=AA=92=E4=BD=93=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=BA=BF=2E202368=29?= Date: Tue, 23 Dec 2014 20:01:03 +0800 Subject: [PATCH 3/4] Fix equivalence --- lib/stomp-node.js | 2 +- src/stomp-node.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stomp-node.js b/lib/stomp-node.js index 4e9e6a2..0800800 100644 --- a/lib/stomp-node.js +++ b/lib/stomp-node.js @@ -46,7 +46,7 @@ socket.on('data', function(data) { var event; data = Buffer.concat([buffer, data]); - if ('\n' !== data.slice(-1)) { + if ('\n' !== data.slice(-1).toString()) { buffer = data; return; } diff --git a/src/stomp-node.coffee b/src/stomp-node.coffee index 0370e24..d31d7d1 100644 --- a/src/stomp-node.coffee +++ b/src/stomp-node.coffee @@ -39,7 +39,7 @@ wrapTCP = (port, host) -> buffer = new Buffer(0) socket.on 'data', (data) -> data = Buffer.concat([buffer, data]) - if ('\n' != data.slice(-1)) + if ('\n' != data.slice(-1).toString()) buffer = data return; From a0a7aa3e0a5fda9624c57cda9603a960a4423948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=91=AB=28=E5=AA=92=E4=BD=93=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E7=BA=BF=2E202368=29?= Date: Tue, 23 Dec 2014 20:08:57 +0800 Subject: [PATCH 4/4] Fix test --- lib/stomp-node.js | 3 ++- src/stomp-node.coffee | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/stomp-node.js b/lib/stomp-node.js index 0800800..2970599 100644 --- a/lib/stomp-node.js +++ b/lib/stomp-node.js @@ -1,7 +1,8 @@ // Generated by CoffeeScript 1.8.0 /* - 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/) */ diff --git a/src/stomp-node.coffee b/src/stomp-node.coffee index d31d7d1..c29f102 100644 --- a/src/stomp-node.coffee +++ b/src/stomp-node.coffee @@ -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/) ### @@ -41,7 +42,7 @@ wrapTCP = (port, host) -> data = Buffer.concat([buffer, data]) if ('\n' != data.slice(-1).toString()) buffer = data - return; + return event = { 'data': data.toString()