diff --git a/microstack/ILibParsers.c b/microstack/ILibParsers.c index 59bfaff..25def95 100644 --- a/microstack/ILibParsers.c +++ b/microstack/ILibParsers.c @@ -948,6 +948,7 @@ typedef struct ILibBaseChain int UnblockFlag; void* auxSelectHandles; HANDLE WaitHandles[FD_SETSIZE * 2]; + HANDLE currentHandle; #else pthread_t ChainThreadID; 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) { ILibChain_WaitHandleInfo *info = (ILibChain_WaitHandleInfo*)waitList[ILibChain_HandleInfoIndex(slct)]; - HANDLE h = waitList[slct]; + ((ILibBaseChain*)chain)->currentHandle = waitList[slct]; waitList[ILibChain_HandleInfoIndex(slct)] = NULL; waitList[slct] = 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 - if (ILibMemory_CanaryOK(info)) + if (((ILibBaseChain*)chain)->currentHandle != NULL && ILibMemory_CanaryOK(info)) { ILibLinkedList_Remove(info->node); } } } + ((ILibBaseChain*)chain)->currentHandle = NULL; } } 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 // set the unblock flag, we'll be good to go // + if (chain->currentHandle == h) { chain->currentHandle = NULL; } ILibLinkedList_Remove(node); chain->UnblockFlag = 1; } diff --git a/microstack/ILibProcessPipe.c b/microstack/ILibProcessPipe.c index ee55a21..52db915 100644 --- a/microstack/ILibProcessPipe.c +++ b/microstack/ILibProcessPipe.c @@ -767,24 +767,31 @@ void ILibProcessPipe_Process_ReadHandler(void* user) int err=0; #ifdef WIN32 - BOOL result; - DWORD bytesRead; + int firstPass = 1; + DWORD bytesRead = 0; UNREFERENCED_PARAMETER(event); #else - int bytesRead; + int bytesRead = 0; #endif pipeObject->processingLoop = 1; do { #ifdef WIN32 err = 0; - result = GetOverlappedResult(pipeObject->mPipe_ReadEnd, pipeObject->mOverlapped, &bytesRead, FALSE); - pipeObject->inProgress = 0; - //printf("Overlapped(%p): %d bytes\n", pipeObject->mPipe_ReadEnd, bytesRead); - if (result == FALSE || bytesRead == 0) + if (firstPass != 0) { - err = GetLastError(); - break; + firstPass = 0; + if (pipeObject->inProgress != 0) + { + if (GetOverlappedResult(pipeObject->mPipe_ReadEnd, pipeObject->mOverlapped, &bytesRead, FALSE) == 0 || bytesRead == 0) + { + pipeObject->inProgress = 0; + err = GetLastError(); + if (err == ERROR_IO_PENDING) { return(TRUE); } + break; + } + pipeObject->inProgress = 0; + } } #else bytesRead = (int)read(pipeObject->mPipe_ReadEnd, pipeObject->buffer + pipeObject->readOffset + pipeObject->totalRead, pipeObject->bufferSize - pipeObject->totalRead); @@ -858,8 +865,9 @@ void ILibProcessPipe_Process_ReadHandler(void* user) if (pipeObject->PAUSED == 0) { 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; } }