mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-16 08:13:30 +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.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
function empty_func()
|
||||||
function dispatch(options)
|
|
||||||
{
|
{
|
||||||
if (!options || !options.modules || !options.launch || !options.launch.module || !options.launch.method || !options.launch.args) { throw ('Invalid Parameters'); }
|
var p = this.parent;
|
||||||
|
p._ipc.parent = null;
|
||||||
var ipcInteger
|
p._ipc2.parent = null;
|
||||||
var ret = { options: options };
|
p._client._parent = null;
|
||||||
require('events').EventEmitter.call(ret, true).createEvent('connection');
|
p._client = null;
|
||||||
|
p._control._parent = null;
|
||||||
ret._ipc = require('net').createServer(); ret._ipc.parent = ret;
|
p._control = null;
|
||||||
ret._ipc2 = require('net').createServer(); ret._ipc2.parent = ret;
|
p = null;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
catch (x)
|
function empty_func2()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
|
||||||
var str = Buffer.from("require('win-console').hide();require('win-dispatcher').connect('" + ipcInteger + "');").toString('base64');
|
function ipc_invoke(method, args)
|
||||||
ret._ipc2.once('connection', function onConnect(s)
|
|
||||||
{
|
|
||||||
this.parent._control = s;
|
|
||||||
this.parent._control._parent = this;
|
|
||||||
this.close();
|
|
||||||
this.parent.invoke = function (method, args)
|
|
||||||
{
|
{
|
||||||
var d, h = Buffer.alloc(4);
|
var d, h = Buffer.alloc(4);
|
||||||
d = Buffer.from(JSON.stringify({ command: 'invoke', value: { method: method, args: args } }));
|
d = Buffer.from(JSON.stringify({ command: 'invoke', value: { method: method, args: args } }));
|
||||||
h.writeUInt32LE(d.length + 4);
|
h.writeUInt32LE(d.length + 4);
|
||||||
this._control.write(h);
|
this._control.write(h);
|
||||||
this._control.write(d);
|
this._control.write(d);
|
||||||
};
|
}
|
||||||
s.on('end', function () { }); // DO NOT DELETE this line
|
|
||||||
});
|
function ipc1_finalized()
|
||||||
ret._ipc.once('connection', function onConnect(s)
|
{
|
||||||
|
//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 = s;
|
||||||
this.parent._client._parent = this;
|
this.parent._client._parent = this;
|
||||||
@@ -78,8 +74,41 @@ function dispatch(options)
|
|||||||
h.writeUInt32LE(d.length + 4);
|
h.writeUInt32LE(d.length + 4);
|
||||||
s.write(h);
|
s.write(h);
|
||||||
s.write(d);
|
s.write(d);
|
||||||
|
s.on('~', ipc1_finalized);
|
||||||
this.parent.emit('connection', s);
|
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
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user