mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-15 15:53:55 +00:00
1. Added NULL check
2. Added process._exit() 3. Fixed CancelIOEx usage
This commit is contained in:
@@ -502,6 +502,18 @@ void ILibDuktape_ScriptContainer_Process_ExitCallback(void *obj)
|
||||
Duktape_SafeDestroyHeap(ctx);
|
||||
}
|
||||
}
|
||||
duk_ret_t ILibDuktape_ScriptContainer_Process_ExitEx(duk_context *ctx)
|
||||
{
|
||||
if (duk_is_number(ctx, 0))
|
||||
{
|
||||
exit(duk_require_int(ctx, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
duk_ret_t ILibDuktape_ScriptContainer_Process_Exit(duk_context *ctx)
|
||||
{
|
||||
void **tmp;
|
||||
@@ -1245,6 +1257,7 @@ void ILibDuktape_ScriptContainer_Process_Init(duk_context *ctx, char **argList)
|
||||
emitter = ILibDuktape_EventEmitter_Create(ctx);
|
||||
ILibDuktape_EventEmitter_CreateEventEx(emitter, "exit");
|
||||
ILibDuktape_CreateProperty_InstanceMethod(ctx, "exit", ILibDuktape_ScriptContainer_Process_Exit, DUK_VARARGS);
|
||||
ILibDuktape_CreateProperty_InstanceMethod(ctx, "_exit", ILibDuktape_ScriptContainer_Process_ExitEx, DUK_VARARGS);
|
||||
ILibDuktape_EventEmitter_CreateEventEx(emitter, "uncaughtException");
|
||||
ILibDuktape_EventEmitter_CreateEventEx(emitter, "SIGTERM");
|
||||
ILibDuktape_EventEmitter_CreateEventEx(emitter, "SIGCHLD");
|
||||
@@ -3271,6 +3284,7 @@ void ILibDuktape_ScriptContainer_StdErrSink(ILibProcessPipe_Process sender, char
|
||||
void **ptr = (void**)ILibMemory_Extra(ILibProcessPipe_Process_GetStdErr(sender));
|
||||
ptr[0] = master;
|
||||
ptr[1] = buffer;
|
||||
|
||||
ILibProcessPipe_Pipe_Pause(ILibProcessPipe_Process_GetStdErr(sender));
|
||||
Duktape_RunOnEventLoop(master->chain, duk_ctx_nonce(master->ctx), master->ctx, ILibDuktape_ScriptContainer_StdErrSink_MicrostackThread, NULL, ptr);
|
||||
}
|
||||
|
||||
@@ -942,6 +942,7 @@ void ILibDuktape_net_server_IPC_ResumeSink(ILibDuktape_DuplexStream *sender, voi
|
||||
{
|
||||
winIPC->unshiftedBytes = 0;
|
||||
ILibDuktape_DuplexStream_WriteData(winIPC->ds, winIPC->buffer + winIPC->bufferOffset, winIPC->bytesLeft);
|
||||
if (winIPC->mPipe == NULL) { return; } // We return here without resetting processingRead, because IO was canceled
|
||||
if (winIPC->unshiftedBytes > 0)
|
||||
{
|
||||
if (winIPC->unshiftedBytes == winIPC->bytesLeft)
|
||||
@@ -1252,7 +1253,6 @@ duk_ret_t ILibDuktape_net_server_listen(duk_context *ctx)
|
||||
duk_del_prop_string(ctx, -1, ILibDuktape_net_WindowsIPC_Buffer);
|
||||
return(ILibDuktape_Error(ctx, "Error Creating Named Pipe: %s", ipc));
|
||||
}
|
||||
|
||||
ConnectNamedPipe(winIPC->mPipeHandle, &winIPC->overlapped);
|
||||
ILibProcessPipe_WaitHandle_Add2(winIPC->manager, winIPC->overlapped.hEvent, winIPC, ILibDuktape_net_server_IPC_ConnectSink);
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ typedef struct ILibProcessPipe_PipeObject
|
||||
void *user1, *user2;
|
||||
#ifdef WIN32
|
||||
int usingCompletionRoutine;
|
||||
int cancelInProgress;
|
||||
HANDLE mPipe_Reader_ResumeEvent;
|
||||
HANDLE mPipe_ReadEnd;
|
||||
HANDLE mPipe_WriteEnd;
|
||||
@@ -584,7 +585,7 @@ void ILibProcessPipe_FreePipe(ILibProcessPipe_PipeObject *pipeObject)
|
||||
#ifdef WIN32
|
||||
if (pipeObject->mPipe_ReadEnd != NULL) { CloseHandle(pipeObject->mPipe_ReadEnd); }
|
||||
if (pipeObject->mPipe_WriteEnd != NULL && pipeObject->mPipe_WriteEnd != pipeObject->mPipe_ReadEnd) { CloseHandle(pipeObject->mPipe_WriteEnd); }
|
||||
if (pipeObject->mOverlapped != NULL) { CloseHandle(pipeObject->mOverlapped->hEvent); free(pipeObject->mOverlapped); }
|
||||
if (pipeObject->mOverlapped != NULL && pipeObject->usingCompletionRoutine == 0) { CloseHandle(pipeObject->mOverlapped->hEvent); free(pipeObject->mOverlapped); }
|
||||
if (pipeObject->mwOverlapped != NULL) { free(pipeObject->mwOverlapped); }
|
||||
if (pipeObject->mPipe_Reader_ResumeEvent != NULL) { CloseHandle(pipeObject->mPipe_Reader_ResumeEvent); }
|
||||
if (pipeObject->buffer != NULL && pipeObject->usingCompletionRoutine == 0) { free(pipeObject->buffer); }
|
||||
@@ -617,7 +618,11 @@ void ILibProcessPipe_FreePipe(ILibProcessPipe_PipeObject *pipeObject)
|
||||
if (pipeObject->mProcess->stdOut == pipeObject) { pipeObject->mProcess->stdOut = NULL; }
|
||||
if (pipeObject->mProcess->stdErr == pipeObject) { pipeObject->mProcess->stdErr = NULL; }
|
||||
}
|
||||
#ifdef WIN32
|
||||
if (pipeObject->usingCompletionRoutine == 0) { ILibMemory_Free(pipeObject); }
|
||||
#else
|
||||
ILibMemory_Free(pipeObject);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -1851,6 +1856,13 @@ void __stdcall ILibProcessPipe_Pipe_Read_CompletionRoutine(DWORD dwErrorCode, DW
|
||||
{
|
||||
ILibProcessPipe_PipeObject *j = (ILibProcessPipe_PipeObject*)((void**)ILibMemory_GetExtraMemory(lpOverlapped, sizeof(OVERLAPPED)))[0];
|
||||
if (!ILibMemory_CanaryOK(j)) { return; }
|
||||
if (j->cancelInProgress != 0)
|
||||
{
|
||||
CloseHandle(j->mOverlapped);
|
||||
free(j->mOverlapped);
|
||||
ILibMemory_Free(j);
|
||||
return;
|
||||
}
|
||||
|
||||
ILibProcessPipe_Pipe_ReadExHandler callback = (ILibProcessPipe_Pipe_ReadExHandler)j->user2;
|
||||
if (callback != NULL) { callback(j, j->user1, dwErrorCode, j->buffer, dwNumberOfBytesTransfered); }
|
||||
@@ -1869,6 +1881,7 @@ int ILibProcessPipe_Pipe_CancelEx(ILibProcessPipe_Pipe targetPipe)
|
||||
{
|
||||
ILibProcessPipe_PipeObject *j = (ILibProcessPipe_PipeObject*)targetPipe;
|
||||
if (!ILibMemory_CanaryOK(j) || j->mPipe_ReadEnd == NULL) { return(2); }
|
||||
j->cancelInProgress = 1;
|
||||
return(CancelIoEx(j->mPipe_ReadEnd, NULL));
|
||||
}
|
||||
int ILibProcessPipe_Pipe_ReadEx(ILibProcessPipe_Pipe targetPipe, char *buffer, int bufferLength, void *user, ILibProcessPipe_Pipe_ReadExHandler OnReadHandler)
|
||||
|
||||
Reference in New Issue
Block a user