mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-20 18:23:21 +00:00
Updated DescriptorEvents to support separate FD_SET watchers
Updated heci.js linux support
This commit is contained in:
@@ -2515,7 +2515,29 @@ duk_ret_t ILibDuktape_DescriptorEvents_Remove(duk_context *ctx)
|
|||||||
duk_push_this(ctx); // [obj]
|
duk_push_this(ctx); // [obj]
|
||||||
duk_get_prop_string(ctx, -1, ILibDuktape_DescriptorEvents_Table); // [obj][table]
|
duk_get_prop_string(ctx, -1, ILibDuktape_DescriptorEvents_Table); // [obj][table]
|
||||||
duk_dup(ctx, 0); // [obj][table][key]
|
duk_dup(ctx, 0); // [obj][table][key]
|
||||||
duk_del_prop(ctx, -2); // [obj][table]
|
if (!duk_is_null_or_undefined(ctx, 1) && duk_is_object(ctx, 1))
|
||||||
|
{
|
||||||
|
duk_get_prop(ctx, -2); // [obj][table][value]
|
||||||
|
if (duk_is_null_or_undefined(ctx, -1)) { return(0); }
|
||||||
|
duk_get_prop_string(ctx, -1, ILibDuktape_DescriptorEvents_Options); //..[table][value][options]
|
||||||
|
if (duk_has_prop_string(ctx, 1, "readset")) { duk_push_false(ctx); duk_put_prop_string(ctx, -2, "readset"); }
|
||||||
|
if (duk_has_prop_string(ctx, 1, "writeset")) { duk_push_false(ctx); duk_put_prop_string(ctx, -2, "writeset"); }
|
||||||
|
if (duk_has_prop_string(ctx, 1, "errorset")) { duk_push_false(ctx); duk_put_prop_string(ctx, -2, "errorset"); }
|
||||||
|
if( Duktape_GetBooleanProperty(ctx, -1, "readset", 0) == 0 &&
|
||||||
|
Duktape_GetBooleanProperty(ctx, -1, "writeset", 0) == 0 &&
|
||||||
|
Duktape_GetBooleanProperty(ctx, -1, "errorset", 0) == 0)
|
||||||
|
{
|
||||||
|
// No FD_SET watchers, so we can remove the entire object
|
||||||
|
duk_pop_2(ctx); // [obj][table]
|
||||||
|
duk_dup(ctx, 0); // [obj][table][key]
|
||||||
|
duk_del_prop(ctx, -2); // [obj][table]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Remove All FD_SET watchers for this FD
|
||||||
|
duk_del_prop(ctx, -2); // [obj][table]
|
||||||
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -2616,6 +2638,20 @@ duk_ret_t ILibDuktape_DescriptorEvents_Add(duk_context *ctx)
|
|||||||
|
|
||||||
duk_push_this(ctx); // [obj]
|
duk_push_this(ctx); // [obj]
|
||||||
duk_get_prop_string(ctx, -1, ILibDuktape_DescriptorEvents_Table); // [obj][table]
|
duk_get_prop_string(ctx, -1, ILibDuktape_DescriptorEvents_Table); // [obj][table]
|
||||||
|
duk_dup(ctx, 0); // [obj][table][key]
|
||||||
|
if (duk_has_prop(ctx, -2)) // [obj][table]
|
||||||
|
{
|
||||||
|
// There's already a watcher, so let's just merge the FD_SETS
|
||||||
|
duk_dup(ctx, 0); // [obj][table][key]
|
||||||
|
duk_get_prop(ctx, -2); // [obj][table][value]
|
||||||
|
duk_get_prop_string(ctx, -1, ILibDuktape_DescriptorEvents_Options); //..[table][value][options]
|
||||||
|
if (Duktape_GetBooleanProperty(ctx, 1, "readset", 0) != 0) { duk_push_true(ctx); duk_put_prop_string(ctx, -2, "readset"); }
|
||||||
|
if (Duktape_GetBooleanProperty(ctx, 1, "writeset", 0) != 0) { duk_push_true(ctx); duk_put_prop_string(ctx, -2, "writeset"); }
|
||||||
|
if (Duktape_GetBooleanProperty(ctx, 1, "errorset", 0) != 0) { duk_push_true(ctx); duk_put_prop_string(ctx, -2, "errorset"); }
|
||||||
|
duk_pop(ctx); // [obj][table][value]
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
duk_push_object(ctx); // [obj][table][value]
|
duk_push_object(ctx); // [obj][table][value]
|
||||||
duk_dup(ctx, 0); // [obj][table][value][key]
|
duk_dup(ctx, 0); // [obj][table][value][key]
|
||||||
duk_dup(ctx, -2); // [obj][table][value][key][value]
|
duk_dup(ctx, -2); // [obj][table][value][key][value]
|
||||||
@@ -2745,7 +2781,7 @@ void ILibDuktape_DescriptorEvents_Push(duk_context *ctx, void *chain)
|
|||||||
((void**)link->ExtraMemoryPtr)[0] = ctx;
|
((void**)link->ExtraMemoryPtr)[0] = ctx;
|
||||||
((void**)link->ExtraMemoryPtr)[1] = duk_get_heapptr(ctx, -1);
|
((void**)link->ExtraMemoryPtr)[1] = duk_get_heapptr(ctx, -1);
|
||||||
ILibDuktape_CreateInstanceMethod(ctx, "addDescriptor", ILibDuktape_DescriptorEvents_Add, 2);
|
ILibDuktape_CreateInstanceMethod(ctx, "addDescriptor", ILibDuktape_DescriptorEvents_Add, 2);
|
||||||
ILibDuktape_CreateInstanceMethod(ctx, "removeDescriptor", ILibDuktape_DescriptorEvents_Remove, 1);
|
ILibDuktape_CreateInstanceMethod(ctx, "removeDescriptor", ILibDuktape_DescriptorEvents_Remove, DUK_VARARGS);
|
||||||
ILibDuktape_CreateInstanceMethod(ctx, "getDescriptorCount", ILibDuktape_DescriptorEvents_GetCount, 0);
|
ILibDuktape_CreateInstanceMethod(ctx, "getDescriptorCount", ILibDuktape_DescriptorEvents_GetCount, 0);
|
||||||
|
|
||||||
ILibAddToChain(chain, link);
|
ILibAddToChain(chain, link);
|
||||||
|
|||||||
@@ -373,12 +373,14 @@ duk_ret_t ILibDuktape_fs_read_readsetSink(duk_context *ctx)
|
|||||||
duk_pop_2(ctx); // [DescriptorEvents][pending]
|
duk_pop_2(ctx); // [DescriptorEvents][pending]
|
||||||
if (duk_get_length(ctx, -1) == 0)
|
if (duk_get_length(ctx, -1) == 0)
|
||||||
{
|
{
|
||||||
// No more pending I/O operations, so we can cleanup the DescriptorEvents
|
// No more pending read I/O operations, so we can cleanup the DescriptorEvents
|
||||||
duk_eval_string(ctx, "require('DescriptorEvents');"); // .....[DescriptorEvents]
|
duk_eval_string(ctx, "require('DescriptorEvents');"); // .....[DescriptorEvents]
|
||||||
duk_get_prop_string(ctx, -1, "removeDescriptor"); // .....[DescriptorEvents][removeDescriptor]
|
duk_get_prop_string(ctx, -1, "removeDescriptor"); // .....[DescriptorEvents][removeDescriptor]
|
||||||
duk_swap_top(ctx, -2); // .....[removeDescriptor][this]
|
duk_swap_top(ctx, -2); // .....[removeDescriptor][this]
|
||||||
duk_push_int(ctx, fd); // .....[removeDescriptor][this][fd]
|
duk_push_int(ctx, fd); // .....[removeDescriptor][this][fd]
|
||||||
duk_pcall_method(ctx, 1); duk_pop(ctx); // [DescriptorEvents][pending]
|
duk_push_object(ctx); // .....[removeDescriptor][this][fd][options]
|
||||||
|
duk_push_true(ctx); duk_put_prop_string(ctx, -2, "readset");//..[removeDescriptor][this][fd][options]
|
||||||
|
duk_pcall_method(ctx, 2); duk_pop(ctx); // [DescriptorEvents][pending]
|
||||||
|
|
||||||
duk_eval_string(ctx, "require('fs');"); // [DescriptorEvents][pending][FS]
|
duk_eval_string(ctx, "require('fs');"); // [DescriptorEvents][pending][FS]
|
||||||
duk_get_prop_string(ctx, -1,FS_EVENT_R_DESCRIPTORS);// [DescriptorEvents][pending][FS][table]
|
duk_get_prop_string(ctx, -1,FS_EVENT_R_DESCRIPTORS);// [DescriptorEvents][pending][FS][table]
|
||||||
@@ -463,7 +465,9 @@ duk_ret_t ILibDuktape_fs_write_writeset_sink(duk_context *ctx)
|
|||||||
duk_get_prop_string(ctx, -1, "removeDescriptor"); // ... [eventdescriptors][remove]
|
duk_get_prop_string(ctx, -1, "removeDescriptor"); // ... [eventdescriptors][remove]
|
||||||
duk_swap_top(ctx, -2); // ... [remove][this]
|
duk_swap_top(ctx, -2); // ... [remove][this]
|
||||||
duk_push_int(ctx, fd); // ... [remove][this][fd]
|
duk_push_int(ctx, fd); // ... [remove][this][fd]
|
||||||
duk_call_method(ctx, 1); // ... [ret]
|
duk_push_object(ctx); // ... [remove][this][fd][options]
|
||||||
|
duk_push_true(ctx); duk_put_prop_string(ctx, -2, "writeset");//[remove][this][fd][options]
|
||||||
|
duk_call_method(ctx, 2); // ... [ret]
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|||||||
117
modules/heci.js
117
modules/heci.js
@@ -299,59 +299,69 @@ function heci_create()
|
|||||||
{
|
{
|
||||||
// Clean up all Handles and Descriptors
|
// Clean up all Handles and Descriptors
|
||||||
console.log('DISCONNECT on ' + this._hashCode());
|
console.log('DISCONNECT on ' + this._hashCode());
|
||||||
|
if (process.platform == 'linux')
|
||||||
|
|
||||||
//
|
|
||||||
// doIoctl()
|
|
||||||
//
|
|
||||||
if (this._descriptorEvent)
|
|
||||||
{
|
{
|
||||||
if (this._overlapped) { require('DescriptorEvents').removeDescriptor(this._overlapped.hEvent); }
|
if(this._descriptor != null)
|
||||||
this._descriptorEvent = null;
|
{
|
||||||
}
|
require('DescriptorEvents').removeDescriptor(this._descriptor);
|
||||||
if (this._overlapped)
|
require('fs').closeSync(this._descriptor);
|
||||||
{
|
this._descriptor = null;
|
||||||
kernel32.CloseHandle(this._overlapped.hEvent);
|
}
|
||||||
this._overlapped = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
if (process.platform == 'win32')
|
||||||
// Read
|
|
||||||
//
|
|
||||||
if (this._rDescriptorEvent)
|
|
||||||
{
|
{
|
||||||
if (this._readoverlapped) { require('DescriptorEvents').removeDescriptor(this._readoverlapped.hEvent); }
|
//
|
||||||
this._rDescriptorEvent = null;
|
// doIoctl()
|
||||||
}
|
//
|
||||||
if (this._readoverlapped)
|
if (this._descriptorEvent)
|
||||||
{
|
{
|
||||||
kernel32.CloseHandle(this._readoverlapped.hEvent);
|
if (this._overlapped) { require('DescriptorEvents').removeDescriptor(this._overlapped.hEvent); }
|
||||||
this._readoverlapped = null;
|
this._descriptorEvent = null;
|
||||||
}
|
}
|
||||||
|
if (this._overlapped)
|
||||||
|
{
|
||||||
|
kernel32.CloseHandle(this._overlapped.hEvent);
|
||||||
|
this._overlapped = null;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Write
|
// Read
|
||||||
//
|
//
|
||||||
if (this._wDescriptorEvent)
|
if (this._rDescriptorEvent)
|
||||||
{
|
{
|
||||||
if (this._writeoverlapped) { require('DescriptorEvents').removeDescriptor(this._writeoverlapped.hEvent); }
|
if (this._readoverlapped) { require('DescriptorEvents').removeDescriptor(this._readoverlapped.hEvent); }
|
||||||
this._wDescriptorEvent = null;
|
this._rDescriptorEvent = null;
|
||||||
}
|
}
|
||||||
if (this._writeoverlapped)
|
if (this._readoverlapped)
|
||||||
{
|
{
|
||||||
kernel32.CloseHandle(this._writeoverlapped.hEvent);
|
kernel32.CloseHandle(this._readoverlapped.hEvent);
|
||||||
this._writeoverlapped = null;
|
this._readoverlapped = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// HECI
|
// Write
|
||||||
//
|
//
|
||||||
if (this._descriptor)
|
if (this._wDescriptorEvent)
|
||||||
{
|
{
|
||||||
kernel32.CloseHandle(this._descriptor);
|
if (this._writeoverlapped) { require('DescriptorEvents').removeDescriptor(this._writeoverlapped.hEvent); }
|
||||||
this._descriptor = null;
|
this._wDescriptorEvent = null;
|
||||||
}
|
}
|
||||||
|
if (this._writeoverlapped)
|
||||||
|
{
|
||||||
|
kernel32.CloseHandle(this._writeoverlapped.hEvent);
|
||||||
|
this._writeoverlapped = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// HECI
|
||||||
|
//
|
||||||
|
if (this._descriptor)
|
||||||
|
{
|
||||||
|
kernel32.CloseHandle(this._descriptor);
|
||||||
|
this._descriptor = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
ret.doIoctl = function doIoctl(code, inputBuffer, outputBuffer, callback)
|
ret.doIoctl = function doIoctl(code, inputBuffer, outputBuffer, callback)
|
||||||
{
|
{
|
||||||
@@ -470,7 +480,7 @@ function heci_create()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
require('fs').write(this._descriptor, chunk.buffer, ret._processWrite_linux_signaled, { metadata: 'heci.session', session: this });
|
require('fs').write(this._descriptor, chunk.buffer, this._processWrite_linux_signaled, { metadata: 'heci.session', session: this });
|
||||||
};
|
};
|
||||||
ret._processWrite_linux_signaled = function _processWrite_linux_signaled(status, bytesWritten, buffer, options)
|
ret._processWrite_linux_signaled = function _processWrite_linux_signaled(status, bytesWritten, buffer, options)
|
||||||
{
|
{
|
||||||
@@ -550,19 +560,8 @@ function heci_create()
|
|||||||
{
|
{
|
||||||
// We can read more, because data is still flowing
|
// We can read more, because data is still flowing
|
||||||
console.log('READING MORE on ' + options.session._hashCode());
|
console.log('READING MORE on ' + options.session._hashCode());
|
||||||
var result = kernel32.ReadFile(this.session._descriptor, this.session._readbuffer, this.session._readbuffer._size, 0, this.session._readoverlapped);
|
options.session._processRead();
|
||||||
if (result.Val != 0 || result._LastError == ERROR_IO_PENDING)
|
|
||||||
{
|
|
||||||
options.session._processRead();
|
|
||||||
return (true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
console.log('Sometype of error: ' + result._LastError);
|
|
||||||
this.session.push(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
ret._processRead = function _processRead()
|
ret._processRead = function _processRead()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user