mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-15 07:43:50 +00:00
1. Removed debug message from child-container
2. Fixed WriteEx() behavior 3. Fixed AddWaitHandle() to use APC if called from wrong thread 4. Fixed net.ipcSocket to return correct value if write completed right away
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1015,7 +1015,7 @@ ILibTransport_DoneState ILibDuktape_net_server_IPC_WriteSink(ILibDuktape_DuplexS
|
||||
if (len == 0)
|
||||
{
|
||||
// No Pending Writes
|
||||
ILibProcessPipe_Pipe_WriteEx(winIPC->mPipe, q, bufferLen, winIPC, ILibDuktape_net_server_IPC_WriteCompletionEvent);
|
||||
return(ILibProcessPipe_Pipe_WriteEx(winIPC->mPipe, q, bufferLen, winIPC, ILibDuktape_net_server_IPC_WriteCompletionEvent));
|
||||
}
|
||||
|
||||
return(ILibTransport_DoneState_INCOMPLETE);
|
||||
@@ -1025,8 +1025,8 @@ void ILibDuktape_net_server_IPC_EndSink(ILibDuktape_DuplexStream *stream, void *
|
||||
if (!ILibMemory_CanaryOK(user)) { return; }
|
||||
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
|
||||
|
||||
if (ILibProcessPipe_Pipe_CancelEx(winIPC->mPipe) == 0)
|
||||
{
|
||||
//if (ILibProcessPipe_Pipe_CancelEx(winIPC->mPipe) == 0)
|
||||
//{
|
||||
ILibProcessPipe_FreePipe(winIPC->mPipe);
|
||||
winIPC->mPipe = NULL; winIPC->mPipeHandle = NULL;
|
||||
if (winIPC->mServer != NULL)
|
||||
@@ -1041,7 +1041,7 @@ void ILibDuktape_net_server_IPC_EndSink(ILibDuktape_DuplexStream *stream, void *
|
||||
duk_get_prop_string(ctx, -1, ILibDuktape_SERVER2LISTENOPTIONS); // [listen][this][options]
|
||||
duk_pcall_method(ctx, 1); duk_pop(ctx); // ...
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
duk_ret_t ILibDuktape_net_server_IPC_ConnectSink_Finalizer(duk_context *ctx)
|
||||
{
|
||||
@@ -1051,7 +1051,7 @@ duk_ret_t ILibDuktape_net_server_IPC_ConnectSink_Finalizer(duk_context *ctx)
|
||||
if (winIPC->mPipe != NULL && winIPC->mPipeHandle != NULL)
|
||||
{
|
||||
// It's ok to do this, becuase the CancelEx happens on the same thread, and the completion routine will use an APC Queue, so the Canary will fail before it tries to deref
|
||||
ILibProcessPipe_Pipe_CancelEx(winIPC->mPipe);
|
||||
//ILibProcessPipe_Pipe_CancelEx(winIPC->mPipe);
|
||||
ILibProcessPipe_FreePipe(winIPC->mPipe);
|
||||
winIPC->mPipe = NULL; winIPC->mPipeHandle = NULL;
|
||||
}
|
||||
|
||||
@@ -2803,8 +2803,33 @@ void *ILibChain_GetObjectForDescriptor(void *chain, int fd)
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
void __stdcall ILibChain_AddWaitHandle_apc(ULONG_PTR u)
|
||||
{
|
||||
void *chain = ((void**)u)[0];
|
||||
HANDLE h = (HANDLE)((void**)u)[1];
|
||||
int msTIMEOUT = (int)(uintptr_t)((void**)u)[2];
|
||||
ILibChain_WaitHandleHandler handler = (ILibChain_WaitHandleHandler)((void**)u)[3];
|
||||
void *user = ((void**)u)[4];
|
||||
|
||||
ILibChain_AddWaitHandle(chain, h, msTIMEOUT, handler, user);
|
||||
|
||||
ILibMemory_Free((void*)u);
|
||||
}
|
||||
void ILibChain_AddWaitHandle(void *chain, HANDLE h, int msTIMEOUT, ILibChain_WaitHandleHandler handler, void *user)
|
||||
{
|
||||
if (!ILibIsRunningOnChainThread(chain))
|
||||
{
|
||||
void **tmp = ILibMemory_SmartAllocate(5 * sizeof(void*));
|
||||
tmp[0] = chain;
|
||||
tmp[1] = h;
|
||||
tmp[2] = (void*)(uintptr_t)msTIMEOUT;
|
||||
tmp[3] = handler;
|
||||
tmp[4] = user;
|
||||
QueueUserAPC((PAPCFUNC)ILibChain_AddWaitHandle_apc, ILibChain_GetMicrostackThreadHandle(chain), (ULONG_PTR)tmp);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void *node = ILibLinkedList_AddTail(((ILibBaseChain*)chain)->auxSelectHandles, h);
|
||||
ILibChain_WaitHandleInfo *info = (ILibChain_WaitHandleInfo*)ILibMemory_Extra(node);
|
||||
info->handler = handler;
|
||||
|
||||
@@ -550,8 +550,14 @@ void ILibProcessPipe_FreePipe(ILibProcessPipe_PipeObject *pipeObject)
|
||||
{
|
||||
if (!ILibMemory_CanaryOK(pipeObject)) { return; }
|
||||
#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->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 && 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); }
|
||||
@@ -1844,13 +1850,13 @@ void __stdcall ILibProcessPipe_Pipe_Write_CompletionRoutine(DWORD dwErrorCode, D
|
||||
((ILibProcessPipe_Pipe_WriteExHandler)j->user4)(j, j->user3, dwErrorCode, dwNumberOfBytesTransfered);
|
||||
}
|
||||
}
|
||||
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_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));
|
||||
//}
|
||||
BOOL ILibProcessPipe_Pipe_ReadEx_sink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, void* user)
|
||||
{
|
||||
ILibProcessPipe_PipeObject *j = (ILibProcessPipe_PipeObject*)user;
|
||||
@@ -1931,7 +1937,7 @@ BOOL ILibProcessPipe_Pipe_WriteEx_sink(void *chain, HANDLE h, ILibWaitHandle_Err
|
||||
}
|
||||
return(FALSE);
|
||||
}
|
||||
int ILibProcessPipe_Pipe_WriteEx(ILibProcessPipe_Pipe targetPipe, char *buffer, int bufferLength, void *user, ILibProcessPipe_Pipe_WriteExHandler OnWriteHandler)
|
||||
ILibTransport_DoneState ILibProcessPipe_Pipe_WriteEx(ILibProcessPipe_Pipe targetPipe, char *buffer, int bufferLength, void *user, ILibProcessPipe_Pipe_WriteExHandler OnWriteHandler)
|
||||
{
|
||||
ILibProcessPipe_PipeObject *j = (ILibProcessPipe_PipeObject*)targetPipe;
|
||||
if (j->mwOverlapped == NULL)
|
||||
@@ -1949,17 +1955,17 @@ int ILibProcessPipe_Pipe_WriteEx(ILibProcessPipe_Pipe targetPipe, char *buffer,
|
||||
if (GetLastError() == ERROR_IO_PENDING)
|
||||
{
|
||||
ILibChain_AddWaitHandle(j->manager->ChainLink.ParentChain, j->mwOverlapped->hEvent, -1, ILibProcessPipe_Pipe_WriteEx_sink, j);
|
||||
return(0);
|
||||
return(ILibTransport_DoneState_INCOMPLETE);
|
||||
}
|
||||
// Error
|
||||
if (OnWriteHandler != NULL) { OnWriteHandler(j, user, 1, 0); }
|
||||
return(1);
|
||||
return(ILibTransport_DoneState_ERROR);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Write completed
|
||||
if (OnWriteHandler != NULL) { OnWriteHandler(j, user, 0, bufferLength); }
|
||||
return(0);
|
||||
return(ILibTransport_DoneState_COMPLETE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ void ILibProcessPipe_Pipe_AddPipeReadHandler(ILibProcessPipe_Pipe targetPipe, in
|
||||
#ifdef WIN32
|
||||
int ILibProcessPipe_Pipe_CancelEx(ILibProcessPipe_Pipe targetPipe);
|
||||
int ILibProcessPipe_Pipe_ReadEx(ILibProcessPipe_Pipe targetPipe, char *buffer, int bufferLength, void *user, ILibProcessPipe_Pipe_ReadExHandler OnReadHandler);
|
||||
int ILibProcessPipe_Pipe_WriteEx(ILibProcessPipe_Pipe targetPipe, char *buffer, int bufferLength, void *user, ILibProcessPipe_Pipe_WriteExHandler OnWriteHandler);
|
||||
ILibTransport_DoneState ILibProcessPipe_Pipe_WriteEx(ILibProcessPipe_Pipe targetPipe, char *buffer, int bufferLength, void *user, ILibProcessPipe_Pipe_WriteExHandler OnWriteHandler);
|
||||
ILibProcessPipe_Pipe ILibProcessPipe_Pipe_CreateFromExistingWithExtraMemory(ILibProcessPipe_Manager manager, HANDLE existingPipe, ILibProcessPipe_Pipe_ReaderHandleType handleType, int extraMemorySize);
|
||||
#define ILibProcessPipe_Pipe_CreateFromExisting(PipeManager, ExistingPipe, HandleType) ILibProcessPipe_Pipe_CreateFromExistingWithExtraMemory(PipeManager, ExistingPipe, HandleType, 0)
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user