Fixed issue with ordered data

This commit is contained in:
jsrobson10 2019-04-19 12:16:37 +10:00
parent cb95fe0b81
commit 3715cfda6b
2 changed files with 12 additions and 22 deletions

32
main.js
View File

@ -152,18 +152,8 @@ function toBytes(buffer)
return bytes; return bytes;
} }
// Recieve helper global varibles
var recieve_buffer = new Buffer.alloc(0);
var recieve_get = false;
var recieve_size = 0;
function recieve_ordered(data, recieve, callback) function recieve_ordered(data, recieve, callback)
{ {
// Recieve helper global varibles
var recieve_buffer = recieve.buffer;
var recieve_get = recieve.get;
var recieve_size = recieve.size;
// Convert the data into a buffer // Convert the data into a buffer
data = toBuffer(data); data = toBuffer(data);
@ -171,39 +161,39 @@ function recieve_ordered(data, recieve, callback)
for(var i=0;i<data.length;i++) for(var i=0;i<data.length;i++)
{ {
// Add the data to the buffer // Add the data to the buffer
recieve_buffer = new Buffer.concat([recieve_buffer, Buffer([data[i]])]); recieve.buffer = new Buffer.concat([recieve.buffer, Buffer([data[i]])]);
// Is the buffer getting data // Is the buffer getting data
if(!recieve_get) if(!recieve.get)
{ {
// Does the buffer contain a number // Does the buffer contain a number
if(recieve_buffer.length >= 4) if(recieve.buffer.length >= 4)
{ {
// Get the number // Get the number
recieve_size = recieve_buffer.readUInt32BE(0); recieve.size = recieve.buffer.readUInt32BE(0);
// Reset the buffer // Reset the buffer
recieve_buffer = new Buffer.alloc(0); recieve.buffer = new Buffer.alloc(0);
// Set the get data mode to true // Set the get data mode to true
recieve_get = true; recieve.get = true;
} }
} }
else else
{ {
// Is the recieve buffer as big as the size // Is the recieve buffer as big as the size
if(recieve_buffer.length == recieve_size) if(recieve.buffer.length == recieve.size)
{ {
// Call the callback // Call the callback
callback(recieve_buffer); callback(recieve.buffer);
// Reset the buffer and the size // Reset the buffer and the size
recieve_buffer = new Buffer.alloc(0); recieve.buffer = new Buffer.alloc(0);
recieve_size = 0; recieve.size = 0;
// Set the get data mode to false // Set the get data mode to false
recieve_get = false; recieve.get = false;
} }
} }
} }

View File

@ -1,5 +1,5 @@
{ {
"encryption_key_size": 10, "encryption_key_size": 16384,
"register_on_fail": true, "register_on_fail": true,
"port": 22068 "port": 22068
} }