mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-15 07:43:50 +00:00
Optimized referencing within win-dispatcher to facilitate better garbage collection
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -14,52 +14,48 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
function dispatch(options)
|
||||
function empty_func()
|
||||
{
|
||||
if (!options || !options.modules || !options.launch || !options.launch.module || !options.launch.method || !options.launch.args) { throw ('Invalid Parameters'); }
|
||||
|
||||
var ipcInteger
|
||||
var ret = { options: options };
|
||||
require('events').EventEmitter.call(ret, true).createEvent('connection');
|
||||
|
||||
ret._ipc = require('net').createServer(); ret._ipc.parent = ret;
|
||||
ret._ipc2 = require('net').createServer(); ret._ipc2.parent = ret;
|
||||
ret._ipc.on('close', function () { });
|
||||
ret._ipc2.on('close', function () { });
|
||||
|
||||
while (true)
|
||||
{
|
||||
ipcInteger = require('tls').generateRandomInteger('1000', '9999');
|
||||
ret._ipcPath = '\\\\.\\pipe\\taskRedirection-' + ipcInteger;
|
||||
|
||||
try
|
||||
{
|
||||
ret._ipc.listen({ path: ret._ipcPath, writableAll: true });
|
||||
ret._ipc2.listen({ path: ret._ipcPath + 'C', writableAll: true });
|
||||
break;
|
||||
var p = this.parent;
|
||||
p._ipc.parent = null;
|
||||
p._ipc2.parent = null;
|
||||
p._client._parent = null;
|
||||
p._client = null;
|
||||
p._control._parent = null;
|
||||
p._control = null;
|
||||
p = null;
|
||||
}
|
||||
catch (x)
|
||||
function empty_func2()
|
||||
{
|
||||
}
|
||||
}
|
||||
var str = Buffer.from("require('win-console').hide();require('win-dispatcher').connect('" + ipcInteger + "');").toString('base64');
|
||||
ret._ipc2.once('connection', function onConnect(s)
|
||||
{
|
||||
this.parent._control = s;
|
||||
this.parent._control._parent = this;
|
||||
this.close();
|
||||
this.parent.invoke = function (method, args)
|
||||
|
||||
function ipc_invoke(method, args)
|
||||
{
|
||||
var d, h = Buffer.alloc(4);
|
||||
d = Buffer.from(JSON.stringify({ command: 'invoke', value: { method: method, args: args } }));
|
||||
h.writeUInt32LE(d.length + 4);
|
||||
this._control.write(h);
|
||||
this._control.write(d);
|
||||
};
|
||||
s.on('end', function () { }); // DO NOT DELETE this line
|
||||
});
|
||||
ret._ipc.once('connection', function onConnect(s)
|
||||
}
|
||||
|
||||
function ipc1_finalized()
|
||||
{
|
||||
//console.log('IPC1 Finalized');
|
||||
}
|
||||
function ipc2_finalized()
|
||||
{
|
||||
//console.log('IPC2 Finalized');
|
||||
}
|
||||
function ipc2_connection(s)
|
||||
{
|
||||
this.parent._control = s;
|
||||
this.parent._control._parent = this;
|
||||
this.close();
|
||||
this.parent.invoke = ipc_invoke;
|
||||
s.on('end', empty_func2); // DO NOT DELETE this line
|
||||
s.on('~', ipc2_finalized);
|
||||
}
|
||||
function ipc_connection(s)
|
||||
{
|
||||
this.parent._client = s;
|
||||
this.parent._client._parent = this;
|
||||
@@ -78,8 +74,41 @@ function dispatch(options)
|
||||
h.writeUInt32LE(d.length + 4);
|
||||
s.write(h);
|
||||
s.write(d);
|
||||
s.on('~', ipc1_finalized);
|
||||
this.parent.emit('connection', s);
|
||||
});
|
||||
}
|
||||
|
||||
function dispatch(options)
|
||||
{
|
||||
if (!options || !options.modules || !options.launch || !options.launch.module || !options.launch.method || !options.launch.args) { throw ('Invalid Parameters'); }
|
||||
|
||||
var ipcInteger
|
||||
var ret = { options: options };
|
||||
require('events').EventEmitter.call(ret, true).createEvent('connection');
|
||||
|
||||
ret._ipc = require('net').createServer(); ret._ipc.parent = ret;
|
||||
ret._ipc2 = require('net').createServer(); ret._ipc2.parent = ret;
|
||||
ret._ipc.on('close', empty_func);
|
||||
ret._ipc2.on('close', empty_func);
|
||||
|
||||
while (true)
|
||||
{
|
||||
ipcInteger = require('tls').generateRandomInteger('1000', '9999');
|
||||
ret._ipcPath = '\\\\.\\pipe\\taskRedirection-' + ipcInteger;
|
||||
|
||||
try
|
||||
{
|
||||
ret._ipc.listen({ path: ret._ipcPath, writableAll: true });
|
||||
ret._ipc2.listen({ path: ret._ipcPath + 'C', writableAll: true });
|
||||
break;
|
||||
}
|
||||
catch (x)
|
||||
{
|
||||
}
|
||||
}
|
||||
var str = Buffer.from("require('win-console').hide();require('win-dispatcher').connect('" + ipcInteger + "');").toString('base64');
|
||||
ret._ipc2.once('connection', ipc2_connection);
|
||||
ret._ipc.once('connection', ipc_connection);
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user