mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-20 02:03:15 +00:00
Fixed so current node can be removed while being dispatched
This commit is contained in:
@@ -948,6 +948,7 @@ typedef struct ILibBaseChain
|
|||||||
int UnblockFlag;
|
int UnblockFlag;
|
||||||
void* auxSelectHandles;
|
void* auxSelectHandles;
|
||||||
HANDLE WaitHandles[FD_SETSIZE * 2];
|
HANDLE WaitHandles[FD_SETSIZE * 2];
|
||||||
|
HANDLE currentHandle;
|
||||||
#else
|
#else
|
||||||
pthread_t ChainThreadID;
|
pthread_t ChainThreadID;
|
||||||
int TerminatePipe[2];
|
int TerminatePipe[2];
|
||||||
@@ -2024,20 +2025,21 @@ int ILibChain_WindowsSelect(void *chain, fd_set *readset, fd_set *writeset, fd_s
|
|||||||
if (waitList[ILibChain_HandleInfoIndex(slct)] != NULL)
|
if (waitList[ILibChain_HandleInfoIndex(slct)] != NULL)
|
||||||
{
|
{
|
||||||
ILibChain_WaitHandleInfo *info = (ILibChain_WaitHandleInfo*)waitList[ILibChain_HandleInfoIndex(slct)];
|
ILibChain_WaitHandleInfo *info = (ILibChain_WaitHandleInfo*)waitList[ILibChain_HandleInfoIndex(slct)];
|
||||||
HANDLE h = waitList[slct];
|
((ILibBaseChain*)chain)->currentHandle = waitList[slct];
|
||||||
waitList[ILibChain_HandleInfoIndex(slct)] = NULL;
|
waitList[ILibChain_HandleInfoIndex(slct)] = NULL;
|
||||||
waitList[slct] = NULL;
|
waitList[slct] = NULL;
|
||||||
if (info->handler != NULL)
|
if (info->handler != NULL)
|
||||||
{
|
{
|
||||||
if (info->handler(chain, h, ILibWaitHandle_ErrorStatus_NONE, info->user) == FALSE)
|
if (info->handler(chain, ((ILibBaseChain*)chain)->currentHandle, ILibWaitHandle_ErrorStatus_NONE, info->user) == FALSE)
|
||||||
{
|
{
|
||||||
// FALSE means to remove tha HANDLE
|
// FALSE means to remove tha HANDLE
|
||||||
if (ILibMemory_CanaryOK(info))
|
if (((ILibBaseChain*)chain)->currentHandle != NULL && ILibMemory_CanaryOK(info))
|
||||||
{
|
{
|
||||||
ILibLinkedList_Remove(info->node);
|
ILibLinkedList_Remove(info->node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
((ILibBaseChain*)chain)->currentHandle = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (slct == WAIT_TIMEOUT)
|
if (slct == WAIT_TIMEOUT)
|
||||||
@@ -3039,6 +3041,7 @@ void __stdcall ILibChain_RemoveWaitHandle_APC(ULONG_PTR u)
|
|||||||
// We found the HANDLE, so if we remove the HANDLE from the list, and
|
// We found the HANDLE, so if we remove the HANDLE from the list, and
|
||||||
// set the unblock flag, we'll be good to go
|
// set the unblock flag, we'll be good to go
|
||||||
//
|
//
|
||||||
|
if (chain->currentHandle == h) { chain->currentHandle = NULL; }
|
||||||
ILibLinkedList_Remove(node);
|
ILibLinkedList_Remove(node);
|
||||||
chain->UnblockFlag = 1;
|
chain->UnblockFlag = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -767,25 +767,32 @@ void ILibProcessPipe_Process_ReadHandler(void* user)
|
|||||||
int err=0;
|
int err=0;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
BOOL result;
|
int firstPass = 1;
|
||||||
DWORD bytesRead;
|
DWORD bytesRead = 0;
|
||||||
UNREFERENCED_PARAMETER(event);
|
UNREFERENCED_PARAMETER(event);
|
||||||
#else
|
#else
|
||||||
int bytesRead;
|
int bytesRead = 0;
|
||||||
#endif
|
#endif
|
||||||
pipeObject->processingLoop = 1;
|
pipeObject->processingLoop = 1;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
err = 0;
|
err = 0;
|
||||||
result = GetOverlappedResult(pipeObject->mPipe_ReadEnd, pipeObject->mOverlapped, &bytesRead, FALSE);
|
if (firstPass != 0)
|
||||||
pipeObject->inProgress = 0;
|
|
||||||
//printf("Overlapped(%p): %d bytes\n", pipeObject->mPipe_ReadEnd, bytesRead);
|
|
||||||
if (result == FALSE || bytesRead == 0)
|
|
||||||
{
|
{
|
||||||
|
firstPass = 0;
|
||||||
|
if (pipeObject->inProgress != 0)
|
||||||
|
{
|
||||||
|
if (GetOverlappedResult(pipeObject->mPipe_ReadEnd, pipeObject->mOverlapped, &bytesRead, FALSE) == 0 || bytesRead == 0)
|
||||||
|
{
|
||||||
|
pipeObject->inProgress = 0;
|
||||||
err = GetLastError();
|
err = GetLastError();
|
||||||
|
if (err == ERROR_IO_PENDING) { return(TRUE); }
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
pipeObject->inProgress = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
bytesRead = (int)read(pipeObject->mPipe_ReadEnd, pipeObject->buffer + pipeObject->readOffset + pipeObject->totalRead, pipeObject->bufferSize - pipeObject->totalRead);
|
bytesRead = (int)read(pipeObject->mPipe_ReadEnd, pipeObject->buffer + pipeObject->readOffset + pipeObject->totalRead, pipeObject->bufferSize - pipeObject->totalRead);
|
||||||
if (bytesRead <= 0)
|
if (bytesRead <= 0)
|
||||||
@@ -858,8 +865,9 @@ void ILibProcessPipe_Process_ReadHandler(void* user)
|
|||||||
if (pipeObject->PAUSED == 0)
|
if (pipeObject->PAUSED == 0)
|
||||||
{
|
{
|
||||||
pipeObject->inProgress = 1;
|
pipeObject->inProgress = 1;
|
||||||
if (ReadFile(pipeObject->mPipe_ReadEnd, pipeObject->buffer + pipeObject->readOffset + pipeObject->totalRead, pipeObject->bufferSize - pipeObject->totalRead, NULL, pipeObject->mOverlapped) != TRUE)
|
if (ReadFile(pipeObject->mPipe_ReadEnd, pipeObject->buffer + pipeObject->readOffset + pipeObject->totalRead, pipeObject->bufferSize - pipeObject->totalRead, &bytesRead, pipeObject->mOverlapped) != TRUE)
|
||||||
{
|
{
|
||||||
|
if (GetLastError() == ERROR_IO_PENDING) { return(TRUE); }
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user