Iscolated ordered data functions.

This commit is contained in:
jsrobson10 2019-04-19 12:16:59 +10:00
parent 45d7fd78d2
commit 067f06c0a2
1 changed files with 20 additions and 18 deletions

View File

@ -171,12 +171,7 @@ function test_socks_test(text)
socket.write(text);
}
// Recieve helper global varibles
var recieve_buffer = new Buffer.alloc(0);
var recieve_get = false;
var recieve_size = 0;
function recieve_ordered(data, callback)
function recieve_ordered(data, recieve, callback)
{
// Convert the data into a buffer
data = toBuffer(data);
@ -185,39 +180,39 @@ function recieve_ordered(data, callback)
for(var i=0;i<data.length;i++)
{
// Add the data to the buffer
recieve_buffer = new Buffer.concat([recieve_buffer, Buffer.from([data[i]])]);
recieve.buffer = new Buffer.concat([recieve.buffer, Buffer([data[i]])]);
// Is the buffer getting data
if(!recieve_get)
if(!recieve.get)
{
// Does the buffer contain a number
if(recieve_buffer.length >= 4)
if(recieve.buffer.length >= 4)
{
// Get the number
recieve_size = recieve_buffer.readUInt32BE(0);
recieve.size = recieve.buffer.readUInt32BE(0);
// Reset the buffer
recieve_buffer = new Buffer.alloc(0);
recieve.buffer = new Buffer.alloc(0);
// Set the get data mode to true
recieve_get = true;
recieve.get = true;
}
}
else
{
// Is the recieve buffer as big as the size
if(recieve_buffer.length == recieve_size)
if(recieve.buffer.length == recieve.size)
{
// Call the callback
callback(recieve_buffer);
callback(recieve.buffer);
// Reset the buffer and the size
recieve_buffer = new Buffer.alloc(0);
recieve_size = 0;
recieve.buffer = new Buffer.alloc(0);
recieve.size = 0;
// Set the get data mode to false
recieve_get = false;
recieve.get = false;
}
}
}
@ -431,11 +426,18 @@ function connect(profile, connection_id)
});
});
// Create the recieve ordered memory model
var recieve_ordered_memory = {
buffer: new Buffer.alloc(0),
get: false,
size: 0
}
// Wait for data
client.on('data', function(data)
{
// Recieve data in order
recieve_ordered(data, function(data)
recieve_ordered(data, recieve_ordered_memory, function(data)
{
/*console.log("RAW: ", {
input: data,