From 4b298f2b949d8e21a49a04c26c2ffb593b3b9941 Mon Sep 17 00:00:00 2001 From: Ben Burry Date: Fri, 10 Oct 2014 17:29:09 +0000 Subject: [PATCH] Buffer incoming tcp data until we receive a complete metric --- servers/tcp.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/servers/tcp.js b/servers/tcp.js index 3c2e651..663b548 100644 --- a/servers/tcp.js +++ b/servers/tcp.js @@ -11,8 +11,15 @@ exports.start = function(config, callback){ var server = net.createServer(function(stream) { stream.setEncoding('ascii'); + var buffer; stream.on('data', function(data) { - callback(data, new rinfo(stream, data)); + buffer += data; + var offset = buffer.lastIndexOf("\n"); + if (offset > -1) { + var packet = buffer.slice(0, offset + 1); + buffer = buffer.slice(offset + 1); + callback(packet, new rinfo(stream, packet)); + } }); });