mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-15 07:43:50 +00:00
Updated metadata handling
This commit is contained in:
@@ -221,6 +221,23 @@ duk_ret_t ILibDuktape_ChildProcess_tcsetsize(duk_context *ctx)
|
||||
}
|
||||
#endif
|
||||
|
||||
duk_ret_t ILibDuktape_SpawnedProcess_descriptorSetter(duk_context *ctx)
|
||||
{
|
||||
duk_push_this(ctx);
|
||||
ILibDuktape_ChildProcess_SubProcess *retVal = (ILibDuktape_ChildProcess_SubProcess*)Duktape_GetBufferProperty(ctx, -1, ILibDuktape_ChildProcess_MemBuf);
|
||||
duk_push_string(ctx, ILibProcessPipe_Process_GetMetadata(retVal->childProcess)); // [string]
|
||||
duk_get_prop_string(ctx, -1, "split"); // [string][split]
|
||||
duk_swap_top(ctx, -2); // [split][this]
|
||||
duk_push_string(ctx, " [EXIT]"); // [split][this][delim]
|
||||
duk_call_method(ctx, 1); // [array]
|
||||
duk_get_prop_string(ctx, -1, "shift"); // [array][shift]
|
||||
duk_swap_top(ctx, -2); // [shift][this]
|
||||
duk_call_method(ctx, 0); // [string]
|
||||
duk_push_sprintf(ctx, "%s, %s", duk_get_string(ctx, -1), duk_require_string(ctx, 0)); // [string][newVal]
|
||||
|
||||
ILibProcessPipe_Process_ResetMetadata(retVal->childProcess, (char*)duk_get_string(ctx, -1));
|
||||
return(0);
|
||||
}
|
||||
ILibDuktape_ChildProcess_SubProcess* ILibDuktape_ChildProcess_SpawnedProcess_PUSH(duk_context *ctx, ILibProcessPipe_Process mProcess, void *callback)
|
||||
{
|
||||
duk_push_object(ctx); // [ChildProcess]
|
||||
@@ -279,6 +296,7 @@ ILibDuktape_ChildProcess_SubProcess* ILibDuktape_ChildProcess_SpawnedProcess_PUS
|
||||
|
||||
if (callback != NULL) { ILibDuktape_EventEmitter_AddOnce(emitter, "exit", callback); }
|
||||
|
||||
ILibProcessPipe_Process_ResetMetadata(mProcess, "childProcess");
|
||||
ILibProcessPipe_Process_AddHandlers(mProcess, 4096, ILibDuktape_ChildProcess_SubProcess_ExitHandler,
|
||||
ILibDuktape_ChildProcess_SubProcess_StdOutHandler,
|
||||
ILibDuktape_ChildProcess_SubProcess_StdErrHandler,
|
||||
@@ -288,6 +306,8 @@ ILibDuktape_ChildProcess_SubProcess* ILibDuktape_ChildProcess_SpawnedProcess_PUS
|
||||
{
|
||||
if (callback != NULL) { ILibDuktape_EventEmitter_AddOnce(emitter, "exit", callback); }
|
||||
}
|
||||
|
||||
ILibDuktape_CreateEventWithSetterEx(ctx, "descriptorMetadata", ILibDuktape_SpawnedProcess_descriptorSetter);
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1028,6 +1028,21 @@ void* ILibMemory_SmartReAllocate(void *ptr, size_t len)
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
void* ILibMemory_SmartAllocateEx_ResizeExtra(void *ptr, size_t newExtraSize)
|
||||
{
|
||||
if (ILibMemory_ExtraSize(ptr) == 0 || newExtraSize == 0) { return(NULL); }
|
||||
size_t rawSize = ILibMemory_RawSize(ptr);
|
||||
size_t size = ILibMemory_Size(ptr);
|
||||
size_t extraSize = ILibMemory_ExtraSize(ptr);
|
||||
|
||||
void *newPtr = ILibMemory_SmartReAllocate(ptr, newExtraSize > extraSize ? size + (newExtraSize - extraSize) : size - (extraSize - newExtraSize));
|
||||
void *rawExtra = (char*)ILibMemory_Extra(newPtr) - sizeof(ILibMemory_Header);
|
||||
memmove_s((char*)newPtr + size, extraSize + sizeof(ILibMemory_Header), rawExtra, extraSize + sizeof(ILibMemory_Header));
|
||||
ILibMemory_Size(newPtr) = size;
|
||||
ILibMemory_ExtraSize(newPtr) = newExtraSize;
|
||||
ILibMemory_Size(ILibMemory_Extra(newPtr)) = newExtraSize;
|
||||
return(newPtr);
|
||||
}
|
||||
void* ILibMemory_Init(void *ptr, size_t primarySize, size_t extraSize, ILibMemory_Types memType)
|
||||
{
|
||||
if (ptr == NULL) { ILIBCRITICALEXIT(254); }
|
||||
@@ -3347,6 +3362,19 @@ void ILibChain_WaitHandle_RestoreState(void *chain, void *state)
|
||||
ILibChain_AddWaitHandleEx(chain, info->node, msTIMEOUT, info->handler, info->user, info->metaData);
|
||||
ILibMemory_Free(info);
|
||||
}
|
||||
void ILibChain_WaitHandle_UpdateMetadata(void *chain, HANDLE h, char *metadata)
|
||||
{
|
||||
size_t metadataLen = strnlen_s(metadata, 1024);
|
||||
void *node = ILibLinkedList_GetNode_Search(((ILibBaseChain*)chain)->auxSelectHandles, NULL, h);
|
||||
if (node != NULL)
|
||||
{
|
||||
void *newNode = ILibLinkedList_Node_ResizeAdditional(node, metadataLen + 1);
|
||||
ILibChain_WaitHandleInfo *info = ILibMemory_Extra(newNode);
|
||||
info->node = newNode;
|
||||
memcpy_s(info->metaData, metadataLen + 1, metadata, metadataLen);
|
||||
}
|
||||
}
|
||||
|
||||
void __stdcall ILibChain_AddWaitHandle_apc(ULONG_PTR u)
|
||||
{
|
||||
void *chain = ((void**)u)[0];
|
||||
@@ -7737,6 +7765,32 @@ void* ILibLinkedList_AddTailEx(void *LinkedList, void *data, size_t additionalSi
|
||||
++r->count;
|
||||
return(newNode);
|
||||
}
|
||||
void* ILibLinkedList_Node_ResizeAdditional(void *node, size_t additionalSize)
|
||||
{
|
||||
size_t baseSize = ILibMemory_GetExtraMemorySize(((ILibLinkedListNode*)node)->Root->ExtraMemory);
|
||||
ILibLinkedListNode* newNode = ILibMemory_SmartAllocateEx_ResizeExtra(node, baseSize + additionalSize);
|
||||
if (newNode != node)
|
||||
{
|
||||
if (newNode->Previous == NULL)
|
||||
{
|
||||
newNode->Root->Head = newNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
newNode->Previous->Next = newNode;
|
||||
}
|
||||
if (newNode->Next == NULL)
|
||||
{
|
||||
newNode->Root->Tail = newNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
newNode->Next->Previous = newNode;
|
||||
}
|
||||
}
|
||||
return(newNode);
|
||||
}
|
||||
|
||||
|
||||
/*! \fn ILibLinkedList_Lock(void *LinkedList)
|
||||
\brief Locks the linked list with a non-recursive lock
|
||||
|
||||
@@ -411,6 +411,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
#define ILibMemory_SmartAllocate(len) ILibMemory_Init(malloc(len+sizeof(ILibMemory_Header)), (int)len, 0, ILibMemory_Types_HEAP)
|
||||
#define ILibMemory_SmartAllocateEx(primaryLen, extraLen) ILibMemory_Init(malloc(primaryLen + extraLen + sizeof(ILibMemory_Header) + (extraLen>0?sizeof(ILibMemory_Header):0)), (int)primaryLen, (int)extraLen, ILibMemory_Types_HEAP)
|
||||
void* ILibMemory_SmartReAllocate(void *ptr, size_t len);
|
||||
void* ILibMemory_SmartAllocateEx_ResizeExtra(void *ptr, size_t extraSize);
|
||||
|
||||
void ILibMemory_Free(void *ptr);
|
||||
void* ILibMemory_AllocateTemp(void* chain, size_t sz);
|
||||
@@ -1005,6 +1006,8 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
void ILibChain_WaitHandle_RestoreState(void *chain, void *state);
|
||||
void ILibChain_WaitHandle_DestroySavedState(void *chain, void *state);
|
||||
BOOL ILibChain_WaitHandleAdded(void *chain, HANDLE h);
|
||||
|
||||
void ILibChain_WaitHandle_UpdateMetadata(void *chain, HANDLE h, 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__))
|
||||
void ILibChain_RemoveWaitHandle(void *chain, HANDLE h);
|
||||
@@ -1231,6 +1234,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
void* ILibLinkedList_AddHead(void *LinkedList, void *data);
|
||||
void* ILibLinkedList_AddTailEx(void *LinkedList, void *data, size_t additionalSize);
|
||||
#define ILibLinkedList_AddTail(LinkedList, data) ILibLinkedList_AddTailEx(LinkedList, data, 0)
|
||||
void* ILibLinkedList_Node_ResizeAdditional(void *node, size_t additionalSize);
|
||||
|
||||
#define ILibLinkedList_Clear(LinkedList) while(ILibLinkedList_GetNode_Head(LinkedList)!=NULL){ILibLinkedList_Remove(ILibLinkedList_GetNode_Head(LinkedList));}
|
||||
|
||||
|
||||
@@ -121,6 +121,8 @@ typedef struct ILibProcessPipe_Process_Object
|
||||
ILibProcessPipe_PipeObject *stdOut;
|
||||
ILibProcessPipe_PipeObject *stdErr;
|
||||
ILibProcessPipe_Process_ExitHandler exitHandler;
|
||||
char *metadata;
|
||||
|
||||
#ifdef WIN32
|
||||
HANDLE hProcess;
|
||||
int hProcess_needAdd;
|
||||
@@ -256,6 +258,7 @@ ILibProcessPipe_Manager ILibProcessPipe_Manager_Create(void *chain)
|
||||
void ILibProcessPipe_FreePipe(ILibProcessPipe_PipeObject *pipeObject)
|
||||
{
|
||||
if (!ILibMemory_CanaryOK(pipeObject)) { return; }
|
||||
ILibMemory_Free(pipeObject->metadata);
|
||||
#ifdef WIN32
|
||||
if (pipeObject->mPipe_ReadEnd != NULL)
|
||||
{
|
||||
@@ -409,6 +412,7 @@ void ILibProcessPipe_Process_Destroy(ILibProcessPipe_Process_Object *p)
|
||||
if (p->stdIn != NULL) { ILibProcessPipe_FreePipe(p->stdIn); }
|
||||
if (p->stdOut != NULL) { ILibProcessPipe_FreePipe(p->stdOut); }
|
||||
if (p->stdErr != NULL) { ILibProcessPipe_FreePipe(p->stdErr); }
|
||||
if (p->metadata != NULL) { ILibMemory_Free(p->metadata); }
|
||||
ILibMemory_Free(p);
|
||||
}
|
||||
#ifndef WIN32
|
||||
@@ -1200,6 +1204,36 @@ BOOL ILibProcessPipe_Process_Pipe_ReadExHandler(void *chain, HANDLE h, ILibWaitH
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void ILibProcessPipe_Pipe_ResetMetadata(ILibProcessPipe_Pipe p, char *metadata)
|
||||
{
|
||||
ILibProcessPipe_PipeObject *pipeObject = (ILibProcessPipe_PipeObject*)p;
|
||||
ILibMemory_Free(pipeObject->metadata);
|
||||
pipeObject->metadata = (char*)ILibMemory_SmartAllocate(strnlen_s(metadata, 1024) + 1);
|
||||
memcpy_s(pipeObject->metadata, ILibMemory_Size(pipeObject->metadata), metadata, ILibMemory_Size(pipeObject->metadata) - 1);
|
||||
|
||||
ILibChain_WaitHandle_UpdateMetadata(pipeObject->mProcess->chain, pipeObject->mOverlapped->hEvent, pipeObject->metadata);
|
||||
}
|
||||
void ILibProcessPipe_Process_ResetMetadata(ILibProcessPipe_Process p, char *metadata)
|
||||
{
|
||||
char tmp[1024];
|
||||
ILibProcessPipe_Process_Object *j = (ILibProcessPipe_Process_Object*)p;
|
||||
|
||||
sprintf_s(tmp, sizeof(tmp), "(stdout) %s", metadata);
|
||||
ILibProcessPipe_Pipe_ResetMetadata(j->stdOut, tmp);
|
||||
|
||||
sprintf_s(tmp, sizeof(tmp), "(stderr) %s", metadata);
|
||||
ILibProcessPipe_Pipe_ResetMetadata(j->stdErr, tmp);
|
||||
|
||||
ILibMemory_Free(j->metadata);
|
||||
j->metadata = (char*)ILibMemory_SmartAllocate(8 + strnlen_s(metadata, 1024));
|
||||
sprintf_s(j->metadata, ILibMemory_Size(j->metadata), "%s [EXIT]", metadata);
|
||||
|
||||
ILibChain_WaitHandle_UpdateMetadata(j->chain, j->hProcess, j->metadata);
|
||||
}
|
||||
char *ILibProcessPipe_Process_GetMetadata(ILibProcessPipe_Process p)
|
||||
{
|
||||
return(((ILibProcessPipe_Process_Object*)p)->metadata);
|
||||
}
|
||||
void ILibProcessPipe_Process_StartPipeReaderEx(ILibProcessPipe_PipeObject *pipeObject, int bufferSize, ILibProcessPipe_GenericReadHandler handler, void* user1, void* user2, char *metadata)
|
||||
{
|
||||
if ((pipeObject->buffer = (char*)malloc(bufferSize)) == NULL) { ILIBCRITICALEXIT(254); }
|
||||
@@ -1207,13 +1241,13 @@ void ILibProcessPipe_Process_StartPipeReaderEx(ILibProcessPipe_PipeObject *pipeO
|
||||
pipeObject->handler = (void*)handler;
|
||||
pipeObject->user1 = user1;
|
||||
pipeObject->user2 = user2;
|
||||
pipeObject->metadata = metadata;
|
||||
if (metadata != NULL) { pipeObject->metadata = metadata; }
|
||||
|
||||
#ifdef WIN32
|
||||
if (pipeObject->mOverlapped != NULL)
|
||||
{
|
||||
// This PIPE supports Overlapped I/O
|
||||
ILibChain_ReadEx2(pipeObject->manager->ChainLink.ParentChain, pipeObject->mPipe_ReadEnd, pipeObject->mOverlapped, pipeObject->buffer, pipeObject->bufferSize, ILibProcessPipe_Process_Pipe_ReadExHandler, pipeObject, metadata);
|
||||
ILibChain_ReadEx2(pipeObject->manager->ChainLink.ParentChain, pipeObject->mPipe_ReadEnd, pipeObject->mOverlapped, pipeObject->buffer, pipeObject->bufferSize, ILibProcessPipe_Process_Pipe_ReadExHandler, pipeObject, pipeObject->metadata);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1312,12 +1346,15 @@ void ILibProcessPipe_Process_AddHandlers(ILibProcessPipe_Process module, int buf
|
||||
j->userObject = user;
|
||||
j->exitHandler = exitHandler;
|
||||
|
||||
ILibProcessPipe_Process_StartPipeReaderEx(j->stdOut, bufferSize, &ILibProcessPipe_Process_PipeHandler_StdOut, j, stdOut, "process_handle_stdout");
|
||||
ILibProcessPipe_Process_StartPipeReaderEx(j->stdErr, bufferSize, &ILibProcessPipe_Process_PipeHandler_StdOut, j, stdErr, "process_handle_stderr");
|
||||
ILibProcessPipe_Process_SetWriteHandler(j->stdIn, &ILibProcessPipe_Process_PipeHandler_StdIn, j, sendOk);
|
||||
if (j->stdOut->metadata == NULL) { j->stdOut->metadata = "process_handle_stdout"; }
|
||||
if (j->stdErr->metadata == NULL) { j->stdOut->metadata = "process_handle_stderr"; }
|
||||
if (j->metadata == NULL) { j->metadata = "process_handle_exit"; }
|
||||
|
||||
ILibProcessPipe_Process_StartPipeReaderEx(j->stdOut, bufferSize, &ILibProcessPipe_Process_PipeHandler_StdOut, j, stdOut, NULL);
|
||||
ILibProcessPipe_Process_StartPipeReaderEx(j->stdErr, bufferSize, &ILibProcessPipe_Process_PipeHandler_StdOut, j, stdErr, NULL);
|
||||
ILibProcessPipe_Process_SetWriteHandler(j->stdIn, &ILibProcessPipe_Process_PipeHandler_StdIn, j, sendOk);
|
||||
#ifdef WIN32
|
||||
ILibChain_AddWaitHandleEx(j->parent->ChainLink.ParentChain, j->hProcess, -1, ILibProcessPipe_Process_OnExit, j, "process_handle_exit");
|
||||
ILibChain_AddWaitHandleEx(j->parent->ChainLink.ParentChain, j->hProcess, -1, ILibProcessPipe_Process_OnExit, j, j->metadata);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,9 @@ void ILibProcessPipe_Process_GetWaitHandles(ILibProcessPipe_Process p, HANDLE *h
|
||||
|
||||
#define ILibProcessPipe_Process_StartPipeReader(pipeObject, bufferSize, handler, user1, user2) ILibProcessPipe_Process_StartPipeReaderEx(pipeObject, bufferSize, handler, user1, user2, ILibChain_MetaData(__FILE__, __LINE__))
|
||||
|
||||
char *ILibProcessPipe_Process_GetMetadata(ILibProcessPipe_Process p);
|
||||
void ILibProcessPipe_Process_ResetMetadata(ILibProcessPipe_Process p, char *metadata);
|
||||
void ILibProcessPipe_Pipe_ResetMetadata(ILibProcessPipe_Pipe p, char *metadata);
|
||||
void ILibProcessPipe_Pipe_Close(ILibProcessPipe_Pipe po);
|
||||
void ILibProcessPipe_Pipe_Pause(ILibProcessPipe_Pipe pipeObject);
|
||||
void ILibProcessPipe_Pipe_Resume(ILibProcessPipe_Pipe pipeObject);
|
||||
|
||||
@@ -56,6 +56,7 @@ function childContainer()
|
||||
set: function (v)
|
||||
{
|
||||
if (this._client) { this._client.descriptorMetadata = v; }
|
||||
if (this._proc) { this._proc.descriptorMetadata = v; }
|
||||
}
|
||||
});
|
||||
ret._ipc = require('net').createServer(); ret._ipc.parent = ret;
|
||||
@@ -164,6 +165,7 @@ function childContainer()
|
||||
}
|
||||
}
|
||||
ret._proc = require('child_process').execFile(process.execPath, [process.execPath.split(process.platform == 'win32' ? '\\' : '/').pop(), '-b64exec', script], child_options);
|
||||
ret._proc.descriptorMetadata = "child-container";
|
||||
ret._proc.parent = ret;
|
||||
ret._proc.stdout.on('data', function (c) { });
|
||||
ret._proc.stderr.on('data', function (c) { });
|
||||
|
||||
@@ -64,7 +64,7 @@ function dispatch(options)
|
||||
this.parent._client._parent = this;
|
||||
this.close();
|
||||
var d, h = Buffer.alloc(4);
|
||||
s.descriptorMetadata = 'win-dispatcher';
|
||||
s.descriptorMetadata = 'win-dispatcher, ' + this.parent.options.launch.module + '.' + this.parent.options.launch.method + '()';
|
||||
|
||||
for (var m in this.parent.options.modules)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user