mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-01-08 19:44:06 +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_get_prop_string(ctx, -1, ILibDuktape_DescriptorEvents_Table); // [obj][table]
|
||||
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);
|
||||
}
|
||||
#ifdef WIN32
|
||||
@@ -2616,6 +2638,20 @@ duk_ret_t ILibDuktape_DescriptorEvents_Add(duk_context *ctx)
|
||||
|
||||
duk_push_this(ctx); // [obj]
|
||||
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_dup(ctx, 0); // [obj][table][value][key]
|
||||
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)[1] = duk_get_heapptr(ctx, -1);
|
||||
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);
|
||||
|
||||
ILibAddToChain(chain, link);
|
||||
|
||||
@@ -373,12 +373,14 @@ duk_ret_t ILibDuktape_fs_read_readsetSink(duk_context *ctx)
|
||||
duk_pop_2(ctx); // [DescriptorEvents][pending]
|
||||
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_get_prop_string(ctx, -1, "removeDescriptor"); // .....[DescriptorEvents][removeDescriptor]
|
||||
duk_swap_top(ctx, -2); // .....[removeDescriptor][this]
|
||||
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_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_swap_top(ctx, -2); // ... [remove][this]
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user