1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-21 18:53:32 +00:00

1. Updated metadata

2. Fixed compiler warning
This commit is contained in:
Bryan Roe
2020-05-21 19:06:05 -07:00
parent dd216efbe8
commit 383c19f5fe
8 changed files with 110 additions and 46 deletions

View File

@@ -4220,16 +4220,16 @@ duk_ret_t ILibDuktape_httpStream_webSocketStream_descriptorMetadata(duk_context
ILibDuktape_WebSocket_State *ws = NULL; ILibDuktape_WebSocket_State *ws = NULL;
duk_push_this(ctx); // [WebSocket_Decoded] duk_push_this(ctx); // [WebSocket_Decoded]
duk_get_prop_string(ctx, -1, ILibDuktape_WSDEC2WS); // [WebSocket_Decoded][WebSocket] duk_get_prop_string(ctx, -1, ILibDuktape_WSDEC2WS); // [WebSocket_Decoded][WebSocket]
ws = (ILibDuktape_WritableStream*)Duktape_GetBufferProperty(ctx, -1, ILibDuktape_WebSocket_StatePtr); ws = (ILibDuktape_WebSocket_State*)Duktape_GetBufferProperty(ctx, -1, ILibDuktape_WebSocket_StatePtr);
if (ws != NULL) if (ws != NULL)
{ {
if (ws->encodedStream->writableStream->pipedReadable == NULL) if (ws->encodedStream->writableStream->pipedReadable == NULL)
{ {
ILibDuktape_Immediate(ctx, (void *[]) { ws, duk_require_string(ctx, 0) }, 2, ILibDuktape_httpStream_webSocketStream_descriptorMetadataEx); ILibDuktape_Immediate(ctx, (void *[]) { ws, (void*)duk_require_string(ctx, 0) }, 2, ILibDuktape_httpStream_webSocketStream_descriptorMetadataEx);
} }
else else
{ {
ILibDuktape_httpStream_webSocketStream_descriptorMetadataEx(ctx, (void *[]) { ws, duk_require_string(ctx, 0) }, 2); ILibDuktape_httpStream_webSocketStream_descriptorMetadataEx(ctx, (void *[]) { ws, (void*)duk_require_string(ctx, 0) }, 2);
} }
} }
return(0); return(0);

File diff suppressed because one or more lines are too long

View File

@@ -95,6 +95,7 @@ typedef struct ILibDuktape_net_WindowsIPC
ILibDuktape_DuplexStream *ds; ILibDuktape_DuplexStream *ds;
BOOL clientConnected; BOOL clientConnected;
void *reservedState; void *reservedState;
char *metadata;
ULONG_PTR _reserved[5]; ULONG_PTR _reserved[5];
char *buffer; char *buffer;
@@ -376,7 +377,7 @@ duk_ret_t ILibDuktape_net_socket_connect(duk_context *ctx)
#ifdef WIN32 #ifdef WIN32
duk_push_this(ctx); duk_push_this(ctx);
duk_push_array(ctx); duk_put_prop_string(ctx, -2, ILibDuktape_net_WindowsIPC_PendingArray); duk_push_array(ctx); duk_put_prop_string(ctx, -2, ILibDuktape_net_WindowsIPC_PendingArray);
ILibDuktape_WriteID(ctx, "net.socket.ipc"); ILibDuktape_WriteID(ctx, "net.ipcSocket");
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)Duktape_PushBuffer(ctx, sizeof(ILibDuktape_net_WindowsIPC)); ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)Duktape_PushBuffer(ctx, sizeof(ILibDuktape_net_WindowsIPC));
duk_put_prop_string(ctx, -2, ILibDuktape_net_WindowsIPC_Buffer); duk_put_prop_string(ctx, -2, ILibDuktape_net_WindowsIPC_Buffer);
@@ -873,7 +874,7 @@ BOOL ILibDuktape_server_ipc_ReadSink(void *chain, HANDLE h, ILibWaitHandle_Error
ILibMemory_ReallocateRaw(&(winIPC->buffer), winIPC->bufferLength == 0 ? ILibDuktape_net_IPC_BUFFERSIZE : winIPC->bufferLength * 2); ILibMemory_ReallocateRaw(&(winIPC->buffer), winIPC->bufferLength == 0 ? ILibDuktape_net_IPC_BUFFERSIZE : winIPC->bufferLength * 2);
winIPC->bufferLength = winIPC->bufferLength == 0 ? ILibDuktape_net_IPC_BUFFERSIZE : winIPC->bufferLength * 2; winIPC->bufferLength = winIPC->bufferLength == 0 ? ILibDuktape_net_IPC_BUFFERSIZE : winIPC->bufferLength * 2;
} }
ILibChain_ReadEx2(chain, h, &(winIPC->read_overlapped), winIPC->buffer + winIPC->bufferOffset + winIPC->totalRead, winIPC->bufferLength - winIPC->totalRead, ILibDuktape_server_ipc_ReadSink, winIPC, "server_ipc_ReadSink()"); ILibChain_ReadEx2(chain, h, &(winIPC->read_overlapped), winIPC->buffer + winIPC->bufferOffset + winIPC->totalRead, winIPC->bufferLength - winIPC->totalRead, ILibDuktape_server_ipc_ReadSink, winIPC, winIPC->metadata);
return(TRUE); return(TRUE);
} }
else else
@@ -885,6 +886,7 @@ BOOL ILibDuktape_server_ipc_ReadSink(void *chain, HANDLE h, ILibWaitHandle_Error
{ {
// I/O Errors // I/O Errors
if (winIPC->mServer != NULL) { winIPC->clientConnected = 0; } if (winIPC->mServer != NULL) { winIPC->clientConnected = 0; }
if (winIPC->reservedState != NULL) { ILibChain_WaitHandle_DestroySavedState(chain, winIPC->reservedState); winIPC->reservedState = NULL; }
ILibDuktape_DuplexStream_Closed(winIPC->ds); ILibDuktape_DuplexStream_Closed(winIPC->ds);
return(FALSE); return(FALSE);
} }
@@ -950,6 +952,8 @@ void ILibDuktape_net_server_IPC_PauseSink(ILibDuktape_DuplexStream *sender, void
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user; ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
winIPC->paused = 1; winIPC->paused = 1;
if (winIPC->mServer != NULL && winIPC->clientConnected == 0) { return; } // Not connected, so just return. Probably unpiping
winIPC->reservedState = ILibChain_WaitHandle_RemoveAndSaveState(winIPC->mChain, winIPC->read_overlapped.hEvent); winIPC->reservedState = ILibChain_WaitHandle_RemoveAndSaveState(winIPC->mChain, winIPC->read_overlapped.hEvent);
} }
void ILibDuktape_net_server_IPC_ResumeSink(ILibDuktape_DuplexStream *sender, void *user) void ILibDuktape_net_server_IPC_ResumeSink(ILibDuktape_DuplexStream *sender, void *user)
@@ -1003,7 +1007,11 @@ void ILibDuktape_net_server_IPC_EndSink(ILibDuktape_DuplexStream *stream, void *
if (!ILibMemory_CanaryOK(user)) { return; } if (!ILibMemory_CanaryOK(user)) { return; }
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user; ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
if (winIPC->mServer != NULL && winIPC->mPipeHandle == NULL) { return; } // Already Closed if (winIPC->mServer != NULL && winIPC->mPipeHandle == NULL) { return; } // Already Closed
if (winIPC->reservedState != NULL)
{
ILibChain_WaitHandle_DestroySavedState(winIPC->mChain, winIPC->reservedState);
winIPC->reservedState = NULL;
}
if (winIPC->mPipeHandle != NULL) if (winIPC->mPipeHandle != NULL)
{ {
if (winIPC->mServer != NULL) { DisconnectNamedPipe(winIPC->mPipeHandle); } if (winIPC->mServer != NULL) { DisconnectNamedPipe(winIPC->mPipeHandle); }
@@ -1056,7 +1064,19 @@ duk_ret_t ILibDuktape_net_server_IPC_ConnectSink_Finalizer(duk_context *ctx)
} }
return(0); return(0);
} }
//BOOL ILibDuktape_net_server_IPC_ConnectSink(HANDLE event, ILibWaitHandle_ErrorStatus status, void* user) duk_ret_t ILibDuktape_net_server_IPC_connection_metadata(duk_context *ctx)
{
duk_push_this(ctx); // [ipcSocket]
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)Duktape_GetBufferProperty(ctx, -1, ILibDuktape_net_WindowsIPC_Buffer);
char *tmp = (char*)duk_push_sprintf(ctx, "%s, %s", winIPC->metadata, (char*)duk_require_string(ctx, 0));
char *tmp2 = (char*)ILibMemory_SmartAllocate(1 + duk_get_length(ctx, -1));
memcpy_s(tmp2, ILibMemory_Size(tmp2), tmp, ILibMemory_Size(tmp2) - 1);
ILibMemory_Free(winIPC->metadata);
winIPC->metadata = tmp2;
return(0);
}
BOOL ILibDuktape_net_server_IPC_ConnectSink(void *chain, HANDLE event, ILibWaitHandle_ErrorStatus status, void* user) BOOL ILibDuktape_net_server_IPC_ConnectSink(void *chain, HANDLE event, ILibWaitHandle_ErrorStatus status, void* user)
{ {
if (ILibMemory_CanaryOK(user) && status == ILibWaitHandle_ErrorStatus_NONE) if (ILibMemory_CanaryOK(user) && status == ILibWaitHandle_ErrorStatus_NONE)
@@ -1065,7 +1085,8 @@ BOOL ILibDuktape_net_server_IPC_ConnectSink(void *chain, HANDLE event, ILibWaitH
winIPC->clientConnected = TRUE; winIPC->clientConnected = TRUE;
ILibDuktape_EventEmitter_SetupEmit(winIPC->ctx, winIPC->mServer, "connection"); // [emit][this][connection] ILibDuktape_EventEmitter_SetupEmit(winIPC->ctx, winIPC->mServer, "connection"); // [emit][this][connection]
duk_push_object(winIPC->ctx); // [emit][this][connection][socket] duk_push_object(winIPC->ctx); // [emit][this][connection][socket]
ILibDuktape_WriteID(winIPC->ctx, "net.socket.ipc"); ILibDuktape_WriteID(winIPC->ctx, "net.ipcSocket");
winIPC->metadata = "net.ipcSocket";
duk_push_heapptr(winIPC->ctx, winIPC->mServer); // [emit][this][connection][socket][server] duk_push_heapptr(winIPC->ctx, winIPC->mServer); // [emit][this][connection][socket][server]
duk_get_prop_string(winIPC->ctx, -1, ILibDuktape_net_WindowsIPC_Buffer); // [emit][this][connection][socket][server][buffer] duk_get_prop_string(winIPC->ctx, -1, ILibDuktape_net_WindowsIPC_Buffer); // [emit][this][connection][socket][server][buffer]
@@ -1080,12 +1101,13 @@ BOOL ILibDuktape_net_server_IPC_ConnectSink(void *chain, HANDLE event, ILibWaitH
ILibDuktape_EventEmitter_AddHook(ILibDuktape_EventEmitter_GetEmitter(winIPC->ctx, -1), "data", ILibDuktape_net_socket_ipc_dataHookCallback); ILibDuktape_EventEmitter_AddHook(ILibDuktape_EventEmitter_GetEmitter(winIPC->ctx, -1), "data", ILibDuktape_net_socket_ipc_dataHookCallback);
ILibDuktape_EventEmitter_AddHook(ILibDuktape_EventEmitter_GetEmitter(winIPC->ctx, -1), "end", ILibDuktape_net_socket_ipc_dataHookCallback); ILibDuktape_EventEmitter_AddHook(ILibDuktape_EventEmitter_GetEmitter(winIPC->ctx, -1), "end", ILibDuktape_net_socket_ipc_dataHookCallback);
ILibDuktape_CreateEventWithSetterEx(winIPC->ctx, "descriptorMetadata", ILibDuktape_net_server_IPC_connection_metadata);
ILibDuktape_EventEmitter_PrependOnce(winIPC->ctx, -1, "~", ILibDuktape_net_server_IPC_ConnectSink_Finalizer); ILibDuktape_EventEmitter_PrependOnce(winIPC->ctx, -1, "~", ILibDuktape_net_server_IPC_ConnectSink_Finalizer);
if (duk_pcall_method(winIPC->ctx, 2) != 0) if (duk_pcall_method(winIPC->ctx, 2) != 0)
{ {
ILibDuktape_Process_UncaughtExceptionEx(winIPC->ctx, "Error emitting net.socket.ipc.connection"); ILibDuktape_Process_UncaughtExceptionEx(winIPC->ctx, "Error emitting net.ipcSocket.connection");
} }
duk_pop(winIPC->ctx); duk_pop(winIPC->ctx);
} }
@@ -1169,6 +1191,10 @@ duk_ret_t ILibDuktape_net_server_listen(duk_context *ctx)
if (ipc != NULL && port == 0) if (ipc != NULL && port == 0)
{ {
duk_push_this(ctx);
ILibDuktape_WriteID(ctx, "net.ipcServer");
duk_pop(ctx);
#if defined(_POSIX) #if defined(_POSIX)
if (ipcLen > sizeof(ipcaddr.sun_path)) { return(ILibDuktape_Error(ctx, "Path too long")); } if (ipcLen > sizeof(ipcaddr.sun_path)) { return(ILibDuktape_Error(ctx, "Path too long")); }
ipcaddr.sun_family = AF_UNIX; ipcaddr.sun_family = AF_UNIX;
@@ -1197,6 +1223,7 @@ duk_ret_t ILibDuktape_net_server_listen(duk_context *ctx)
winIPC->mServer = duk_get_heapptr(ctx, -1); winIPC->mServer = duk_get_heapptr(ctx, -1);
winIPC->mChain = duk_ctx_chain(ctx); winIPC->mChain = duk_ctx_chain(ctx);
winIPC->clientConnected = FALSE; winIPC->clientConnected = FALSE;
winIPC->metadata = "net.ipcServer";
duk_eval_string(ctx, "require('child_process');"); duk_eval_string(ctx, "require('child_process');");
duk_pop(ctx); duk_pop(ctx);
@@ -1237,7 +1264,7 @@ duk_ret_t ILibDuktape_net_server_listen(duk_context *ctx)
} }
//printf("ConnectNamedPipe(%s)\n", ipc); //printf("ConnectNamedPipe(%s)\n", ipc);
ConnectNamedPipe(winIPC->mPipeHandle, &winIPC->overlapped); ConnectNamedPipe(winIPC->mPipeHandle, &winIPC->overlapped);
ILibChain_AddWaitHandleEx(duk_ctx_chain(ctx), winIPC->overlapped.hEvent, -1, ILibDuktape_net_server_IPC_ConnectSink, winIPC, "net_server_listen()"); ILibChain_AddWaitHandleEx(duk_ctx_chain(ctx), winIPC->overlapped.hEvent, -1, ILibDuktape_net_server_IPC_ConnectSink, winIPC, "net.ipcServer [listen]");
if (pIPC_SA != NULL) { LocalFree(IPC_ACL); } if (pIPC_SA != NULL) { LocalFree(IPC_ACL); }
return(1); return(1);
@@ -1299,6 +1326,8 @@ duk_ret_t ILibDuktape_net_server_listen(duk_context *ctx)
#endif #endif
duk_push_this(ctx); duk_push_this(ctx);
if (server->server != NULL) { ILibChain_Link_SetMetadata(server->server, Duktape_GetStringPropertyValue(ctx, -1, ILibDuktape_OBJID, "net.Server")); }
return 1; return 1;
} }
duk_ret_t ILibDuktape_net_server_Finalizer(duk_context *ctx) duk_ret_t ILibDuktape_net_server_Finalizer(duk_context *ctx)
@@ -1425,6 +1454,21 @@ duk_ret_t ILibDuktape_net_server_listening(duk_context *ctx)
return(1); return(1);
} }
duk_ret_t ILibDuktape_net_createServer_metadata(duk_context *ctx)
{
duk_push_this(ctx); // [serverSocket]
ILibDuktape_net_server *server = (ILibDuktape_net_server*)Duktape_GetBufferProperty(ctx, -1, ILibDuktape_net_Server_buffer);
if (server->server != NULL)
{
// Non-IPC Server
char *tmp = (char*)duk_push_sprintf(ctx, "%s, %s", ILibChain_Link_GetMetadata(server->server), (char*)duk_require_string(ctx, 0));
char *tmp2 = (char*)ILibMemory_SmartAllocate(duk_get_length(ctx, -1) + 1);
memcpy_s(tmp2, ILibMemory_Size(tmp2), tmp, ILibMemory_Size(tmp2) - 1);
ILibChain_Link_SetMetadata(server->server, tmp2);
}
return(0);
}
duk_ret_t ILibDuktape_net_createServer(duk_context *ctx) duk_ret_t ILibDuktape_net_createServer(duk_context *ctx)
{ {
int nargs = duk_get_top(ctx); int nargs = duk_get_top(ctx);
@@ -1465,6 +1509,7 @@ duk_ret_t ILibDuktape_net_createServer(duk_context *ctx)
ILibDuktape_EventEmitter_CreateEventEx(server->emitter, "error"); ILibDuktape_EventEmitter_CreateEventEx(server->emitter, "error");
ILibDuktape_EventEmitter_CreateEventEx(server->emitter, "listening"); ILibDuktape_EventEmitter_CreateEventEx(server->emitter, "listening");
ILibDuktape_CreateEventWithGetter(ctx, "listening", ILibDuktape_net_server_listening); ILibDuktape_CreateEventWithGetter(ctx, "listening", ILibDuktape_net_server_listening);
ILibDuktape_CreateEventWithSetterEx(ctx, "descriptorMetadata", ILibDuktape_net_createServer_metadata);
ILibDuktape_CreateInstanceMethod(ctx, "listen", ILibDuktape_net_server_listen, DUK_VARARGS); ILibDuktape_CreateInstanceMethod(ctx, "listen", ILibDuktape_net_server_listen, DUK_VARARGS);
ILibDuktape_CreateInstanceMethod(ctx, "address", ILibDuktape_net_server_address, 0); ILibDuktape_CreateInstanceMethod(ctx, "address", ILibDuktape_net_server_address, 0);

View File

@@ -927,8 +927,8 @@ typedef struct ILibChain_WaitHandleInfo
void *node; void *node;
ILibChain_WaitHandleHandler handler; ILibChain_WaitHandleHandler handler;
void *user; void *user;
char *metadata;
struct timeval expiration; struct timeval expiration;
char metaData[];
}ILibChain_WaitHandleInfo; }ILibChain_WaitHandleInfo;
#endif #endif
@@ -2046,7 +2046,6 @@ int ILibChain_WindowsSelect(void *chain, fd_set *readset, fd_set *writeset, fd_s
// FALSE means to remove tha HANDLE // FALSE means to remove tha HANDLE
if (((ILibBaseChain*)chain)->currentHandle != NULL && ILibMemory_CanaryOK(info)) if (((ILibBaseChain*)chain)->currentHandle != NULL && ILibMemory_CanaryOK(info))
{ {
ILibMemory_Free(info->metadata);
ILibLinkedList_Remove(info->node); ILibLinkedList_Remove(info->node);
} }
} }
@@ -3029,18 +3028,18 @@ char *ILibChain_GetMetaDataFromDescriptorSetEx(void *chain, fd_set *inr, fd_set
#ifdef WIN32 #ifdef WIN32
SOCKET slist[FD_SETSIZE]; SOCKET slist[FD_SETSIZE];
int scount = 0; int scount = 0;
for (f = 0; f < readset.fd_count; ++f) for (f = 0; f < (int)readset.fd_count; ++f)
{ {
slist[scount++] = readset.fd_array[f]; slist[scount++] = readset.fd_array[f];
} }
for (f = 0; f < writeset.fd_count; ++f) for (f = 0; f < (int)writeset.fd_count; ++f)
{ {
if (FD_ISSET(writeset.fd_array[f], &readset) == 0) if (FD_ISSET(writeset.fd_array[f], &readset) == 0)
{ {
slist[scount++] = writeset.fd_array[f]; slist[scount++] = writeset.fd_array[f];
} }
} }
for (f = 0; f < errorset.fd_count; ++f) for (f = 0; f < (int)errorset.fd_count; ++f)
{ {
if (FD_ISSET(errorset.fd_array[f], &readset) == 0 && FD_ISSET(errorset.fd_array[f], &writeset) == 0) if (FD_ISSET(errorset.fd_array[f], &readset) == 0 && FD_ISSET(errorset.fd_array[f], &writeset) == 0)
{ {
@@ -3071,7 +3070,7 @@ char *ILibChain_GetMetaDataFromDescriptorSetEx(void *chain, fd_set *inr, fd_set
{ {
if (bchain->WaitHandles[f] != NULL && bchain->WaitHandles[ILibChain_HandleInfoIndex(f)] != NULL) if (bchain->WaitHandles[f] != NULL && bchain->WaitHandles[ILibChain_HandleInfoIndex(f)] != NULL)
{ {
len += sprintf_s(retStr + len, ILibMemory_Size(retStr) - len, " H[%p] (Signaled: %d) => %s\n", bchain->WaitHandles[f], WaitForSingleObjectEx(bchain->WaitHandles[f], 0, FALSE) == 0, ((ILibChain_WaitHandleInfo*)bchain->WaitHandles[ILibChain_HandleInfoIndex(f)])->metadata); len += sprintf_s(retStr + len, ILibMemory_Size(retStr) - len, " H[%p] (Signaled: %d) => %s\n", bchain->WaitHandles[f], WaitForSingleObjectEx(bchain->WaitHandles[f], 0, FALSE) == 0, ((ILibChain_WaitHandleInfo*)bchain->WaitHandles[ILibChain_HandleInfoIndex(f)])->metaData);
} }
} }
#endif #endif
@@ -3192,6 +3191,12 @@ BOOL ILibChain_ReadEx_Sink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus sta
DWORD bytesRead = 0; DWORD bytesRead = 0;
DWORD err; DWORD err;
if (status == ILibWaitHandle_ErrorStatus_REMOVED)
{
ILibMemory_Free(data);
return(FALSE);
}
if (GetOverlappedResult(data->fileHandle, data->p, &bytesRead, FALSE) && bytesRead > 0) if (GetOverlappedResult(data->fileHandle, data->p, &bytesRead, FALSE) && bytesRead > 0)
{ {
if (data->handler != NULL) { data->handler(chain, data->fileHandle, ILibWaitHandle_ErrorStatus_NONE, data->buffer, bytesRead, data->user); } if (data->handler != NULL) { data->handler(chain, data->fileHandle, ILibWaitHandle_ErrorStatus_NONE, data->buffer, bytesRead, data->user); }
@@ -3260,7 +3265,10 @@ void ILibChain_ReadEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, int b
state->handler = handler; state->handler = handler;
state->fileHandle = h; state->fileHandle = h;
state->user = user; state->user = user;
ILibChain_AddWaitHandleEx(chain, p->hEvent, -1, ILibChain_ReadEx_Sink, state, metadata); char *m = ILibMemory_SmartAllocate(10 + strnlen_s(metadata, 1024));
sprintf_s(m, ILibMemory_Size(m), "%s [READ]", metadata == NULL ? "" : metadata);
ILibChain_AddWaitHandleEx(chain, p->hEvent, -1, ILibChain_ReadEx_Sink, state, m);
ILibMemory_Free(m);
} }
else else
{ {
@@ -3285,13 +3293,22 @@ BOOL ILibChain_WaitHandleAdded(void *chain, HANDLE h)
{ {
return(ILibLinkedList_GetNode_Search(((ILibBaseChain*)chain)->auxSelectHandles, NULL, h) != NULL); return(ILibLinkedList_GetNode_Search(((ILibBaseChain*)chain)->auxSelectHandles, NULL, h) != NULL);
} }
void ILibChain_WaitHandle_DestroySavedState(void *chain, void *state)
{
if (state != NULL)
{
ILibChain_WaitHandleInfo *info = (ILibChain_WaitHandleInfo*)state;
info->handler(chain, info->node, ILibWaitHandle_ErrorStatus_REMOVED, info->user);
ILibMemory_Free(info);
}
}
void* ILibChain_WaitHandle_RemoveAndSaveState(void *chain, HANDLE h) void* ILibChain_WaitHandle_RemoveAndSaveState(void *chain, HANDLE h)
{ {
ILibChain_WaitHandleInfo *ret = NULL; ILibChain_WaitHandleInfo *ret = NULL;
void *node = ILibLinkedList_GetNode_Search(((ILibBaseChain*)chain)->auxSelectHandles, NULL, h); void *node = ILibLinkedList_GetNode_Search(((ILibBaseChain*)chain)->auxSelectHandles, NULL, h);
if (node != NULL) if (node != NULL)
{ {
ret = (ILibChain_WaitHandleInfo*)ILibMemory_SmartAllocate(sizeof(ILibChain_WaitHandleInfo)); ret = (ILibChain_WaitHandleInfo*)ILibMemory_SmartAllocate(ILibMemory_ExtraSize(node));
memcpy_s(ret, ILibMemory_Size(ret), ILibMemory_Extra(node), ILibMemory_Size(ret)); memcpy_s(ret, ILibMemory_Size(ret), ILibMemory_Extra(node), ILibMemory_Size(ret));
ret->node = h; ret->node = h;
ILibLinkedList_Remove(node); ILibLinkedList_Remove(node);
@@ -3327,7 +3344,7 @@ void ILibChain_WaitHandle_RestoreState(void *chain, void *state)
} }
} }
ILibChain_AddWaitHandleEx(chain, info->node, msTIMEOUT, info->handler, info->user, info->metadata); ILibChain_AddWaitHandleEx(chain, info->node, msTIMEOUT, info->handler, info->user, info->metaData);
ILibMemory_Free(info); ILibMemory_Free(info);
} }
void __stdcall ILibChain_AddWaitHandle_apc(ULONG_PTR u) void __stdcall ILibChain_AddWaitHandle_apc(ULONG_PTR u)
@@ -3362,17 +3379,16 @@ void ILibChain_AddWaitHandleEx(void *chain, HANDLE h, int msTIMEOUT, ILibChain_W
if (((ILibBaseChain*)chain)->currentHandle != h) if (((ILibBaseChain*)chain)->currentHandle != h)
{ {
void *node = ILibLinkedList_AddTail(((ILibBaseChain*)chain)->auxSelectHandles, h); void *node = ILibLinkedList_AddTailEx(((ILibBaseChain*)chain)->auxSelectHandles, h, metadata==NULL?1:1+strnlen_s(metadata, 1024));
info = (ILibChain_WaitHandleInfo*)ILibMemory_Extra(node); info = (ILibChain_WaitHandleInfo*)ILibMemory_Extra(node);
info->node = node; info->node = node;
info->metadata = metadata; memcpy_s(info->metaData, ILibMemory_ExtraSize(node) - sizeof(ILibChain_WaitHandleInfo), metadata == NULL ? "" : metadata, ILibMemory_ExtraSize(node) - sizeof(ILibChain_WaitHandleInfo));
ILibForceUnBlockChain(chain); ILibForceUnBlockChain(chain);
} }
else else
{ {
((ILibBaseChain*)chain)->currentHandle = NULL; ((ILibBaseChain*)chain)->currentHandle = NULL;
info = ((ILibBaseChain*)chain)->currentInfo; info = ((ILibBaseChain*)chain)->currentInfo;
info->metadata = metadata;
} }
if (info != NULL) if (info != NULL)
{ {
@@ -3403,10 +3419,6 @@ void __stdcall ILibChain_RemoveWaitHandle_APC(ULONG_PTR u)
chain->currentHandle = NULL; chain->currentInfo = NULL; chain->currentHandle = NULL; chain->currentInfo = NULL;
} }
ILibChain_WaitHandleInfo *info = (ILibChain_WaitHandleInfo*)ILibMemory_Extra(node); ILibChain_WaitHandleInfo *info = (ILibChain_WaitHandleInfo*)ILibMemory_Extra(node);
if (info != NULL)
{
ILibMemory_Free(info->metadata);
}
ILibLinkedList_Remove(node); ILibLinkedList_Remove(node);
chain->UnblockFlag = 1; chain->UnblockFlag = 1;
} }
@@ -7456,11 +7468,12 @@ void* ILibLinkedList_GetTag(ILibLinkedList list)
return(((struct ILibLinkedListNode_Root*)list)->Tag); return(((struct ILibLinkedListNode_Root*)list)->Tag);
} }
void* ILibLinkedList_AllocateNode(void *LinkedList) void* ILibLinkedList_AllocateNodeEx(void *LinkedList, size_t extraSize)
{ {
void* newNode = ILibMemory_SmartAllocateEx(sizeof(ILibLinkedListNode), ILibMemory_GetExtraMemorySize(((ILibLinkedListNode_Root*)LinkedList)->ExtraMemory)); void* newNode = ILibMemory_SmartAllocateEx(sizeof(ILibLinkedListNode), extraSize + ILibMemory_GetExtraMemorySize(((ILibLinkedListNode_Root*)LinkedList)->ExtraMemory));
return(newNode); return(newNode);
} }
#define ILibLinkedList_AllocateNode(linkedList) ILibLinkedList_AllocateNodeEx(linkedList, 0)
void* ILibLinkedList_GetExtendedMemory(void* LinkedList_Node) void* ILibLinkedList_GetExtendedMemory(void* LinkedList_Node)
{ {
@@ -7707,12 +7720,12 @@ void* ILibLinkedList_AddHead(void *LinkedList, void *data)
\param LinkedList The linked list \param LinkedList The linked list
\param data The data pointer to reference \param data The data pointer to reference
*/ */
void* ILibLinkedList_AddTail(void *LinkedList, void *data) void* ILibLinkedList_AddTailEx(void *LinkedList, void *data, size_t additionalSize)
{ {
struct ILibLinkedListNode_Root *r = (struct ILibLinkedListNode_Root*)LinkedList; struct ILibLinkedListNode_Root *r = (struct ILibLinkedListNode_Root*)LinkedList;
struct ILibLinkedListNode *newNode; struct ILibLinkedListNode *newNode;
newNode = ILibLinkedList_AllocateNode(r); newNode = ILibLinkedList_AllocateNodeEx(r, additionalSize);
newNode->Data = data; newNode->Data = data;
newNode->Root = r; newNode->Root = r;
newNode->Next = NULL; newNode->Next = NULL;

View File

@@ -1003,6 +1003,7 @@ int ILibIsRunningOnChainThread(void* chain);
void* ILibChain_WaitHandle_RemoveAndSaveState(void *chain, HANDLE h); void* ILibChain_WaitHandle_RemoveAndSaveState(void *chain, HANDLE h);
void ILibChain_WaitHandle_RestoreState(void *chain, void *state); void ILibChain_WaitHandle_RestoreState(void *chain, void *state);
void ILibChain_WaitHandle_DestroySavedState(void *chain, void *state);
BOOL ILibChain_WaitHandleAdded(void *chain, HANDLE h); BOOL ILibChain_WaitHandleAdded(void *chain, HANDLE h);
void ILibChain_AddWaitHandleEx(void *chain, HANDLE h, int msTIMEOUT, ILibChain_WaitHandleHandler handler, void *user, char *metadata); void ILibChain_AddWaitHandleEx(void *chain, HANDLE h, int msTIMEOUT, ILibChain_WaitHandleHandler handler, void *user, char *metadata);
#define ILibChain_AddWaitHandle(chain, h, msTIMEOUT, handler, user) ILibChain_AddWaitHandleEx(chain, h, msTIMEOUT, handler, user, ILibChain_MetaData(__FILE__, __LINE__)) #define ILibChain_AddWaitHandle(chain, h, msTIMEOUT, handler, user) ILibChain_AddWaitHandleEx(chain, h, msTIMEOUT, handler, user, ILibChain_MetaData(__FILE__, __LINE__))
@@ -1228,7 +1229,9 @@ int ILibIsRunningOnChainThread(void* chain);
void* ILibLinkedList_Remove(void *LinkedList_Node); void* ILibLinkedList_Remove(void *LinkedList_Node);
int ILibLinkedList_Remove_ByData(void *LinkedList, void *data); int ILibLinkedList_Remove_ByData(void *LinkedList, void *data);
void* ILibLinkedList_AddHead(void *LinkedList, void *data); void* ILibLinkedList_AddHead(void *LinkedList, void *data);
void* ILibLinkedList_AddTail(void *LinkedList, void *data); void* ILibLinkedList_AddTailEx(void *LinkedList, void *data, size_t additionalSize);
#define ILibLinkedList_AddTail(LinkedList, data) ILibLinkedList_AddTailEx(LinkedList, data, 0)
#define ILibLinkedList_Clear(LinkedList) while(ILibLinkedList_GetNode_Head(LinkedList)!=NULL){ILibLinkedList_Remove(ILibLinkedList_GetNode_Head(LinkedList));} #define ILibLinkedList_Clear(LinkedList) while(ILibLinkedList_GetNode_Head(LinkedList)!=NULL){ILibLinkedList_Remove(ILibLinkedList_GetNode_Head(LinkedList));}
void ILibLinkedList_Lock(void *LinkedList); void ILibLinkedList_Lock(void *LinkedList);

View File

@@ -52,7 +52,12 @@ function childContainer()
this._client.write(h); this._client.write(h);
this._client.write(d); this._client.write(d);
}); });
Object.defineProperty(ret, "descriptorMetadata", {
set: function (v)
{
if (this._client) { this._client.descriptorMetadata = v; }
}
});
ret._ipc = require('net').createServer(); ret._ipc.parent = ret; ret._ipc = require('net').createServer(); ret._ipc.parent = ret;
ret._ipc.on('close', function () { console.log('Child Container Process Closed'); }); ret._ipc.on('close', function () { console.log('Child Container Process Closed'); });
@@ -83,6 +88,7 @@ function childContainer()
var script = Buffer.from("console.log('CHILD/START');require('child-container').connect('" + ipcInteger + "');").toString('base64'); var script = Buffer.from("console.log('CHILD/START');require('child-container').connect('" + ipcInteger + "');").toString('base64');
ret._ipc.once('connection', function onConnect(s) ret._ipc.once('connection', function onConnect(s)
{ {
s.descriptorMetadata = 'child-container';
this.parent._client = s; this.parent._client = s;
this.parent._client._parent = this; this.parent._client._parent = this;
var data; var data;
@@ -94,11 +100,6 @@ function childContainer()
data = { command: 'launch', value: { module: this.parent.options.launch.module, method: this.parent.options.launch.method, args: this.parent.options.launch.args } }; data = { command: 'launch', value: { module: this.parent.options.launch.module, method: this.parent.options.launch.method, args: this.parent.options.launch.args } };
this.parent.send(data); this.parent.send(data);
s.once('close', function ()
{
console.log('close emitted');
require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: 'close emitted'});
});
s.on('data', function (c) s.on('data', function (c)
{ {
var cLen; var cLen;

View File

@@ -74,6 +74,7 @@ function messageBox()
ret._ipc.master = ret; ret._ipc.master = ret;
ret._ipc.on('ready', function () ret._ipc.on('ready', function ()
{ {
this.descriptorMetadata = 'message-box';
if (this.master.timeout != null) { this.master._timeout = setTimeout(function (mstr) { mstr._ipc.exit(); }, this.master.timeout * 1000, this.master); } if (this.master.timeout != null) { this.master._timeout = setTimeout(function (mstr) { mstr._ipc.exit(); }, this.master.timeout * 1000, this.master); }
if (this.master.layout == null) if (this.master.layout == null)
{ {

View File

@@ -64,6 +64,7 @@ function dispatch(options)
this.parent._client._parent = this; this.parent._client._parent = this;
this.close(); this.close();
var d, h = Buffer.alloc(4); var d, h = Buffer.alloc(4);
s.descriptorMetadata = 'win-dispatcher';
for (var m in this.parent.options.modules) for (var m in this.parent.options.modules)
{ {