1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-11 05:43:33 +00:00

Updated metadata for descriptor tracking

This commit is contained in:
Bryan Roe
2020-05-19 17:21:07 -07:00
parent f6c254bd4c
commit f2d63ea116
4 changed files with 31 additions and 9 deletions

View File

@@ -2039,6 +2039,7 @@ int ILibChain_WindowsSelect(void *chain, fd_set *readset, fd_set *writeset, fd_s
// FALSE means to remove tha HANDLE // FALSE means to remove tha HANDLE
if (((ILibBaseChain*)chain)->currentHandle != NULL && ILibMemory_CanaryOK(info)) if (((ILibBaseChain*)chain)->currentHandle != NULL && ILibMemory_CanaryOK(info))
{ {
ILibMemory_Free(info->metadata);
ILibLinkedList_Remove(info->node); ILibLinkedList_Remove(info->node);
} }
} }
@@ -3103,6 +3104,12 @@ void *ILibChain_GetObjectForDescriptor(void *chain, int fd)
return(ret); return(ret);
} }
char *ILibChain_MetaData(char *file, int number)
{
char *ret = ILibMemory_SmartAllocate(strnlen_s(file, 1024) + 16);
sprintf_s(ret, ILibMemory_Size(ret), "%s:%d", file, number);
return(ret);
}
#ifdef WIN32 #ifdef WIN32
BOOL ILibChain_WriteEx_Sink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, void *user); BOOL ILibChain_WriteEx_Sink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, void *user);
BOOL ILibChain_WriteEx_Sink2(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, int bytesWritten, void *user) BOOL ILibChain_WriteEx_Sink2(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, int bytesWritten, void *user)
@@ -3123,6 +3130,7 @@ BOOL ILibChain_WriteEx_Sink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus st
{ {
// Done Writing // Done Writing
if (data->handler != NULL) { data->handler(chain, data->fileHandle, ILibWaitHandle_ErrorStatus_NONE, data->totalWritten, data->user); } if (data->handler != NULL) { data->handler(chain, data->fileHandle, ILibWaitHandle_ErrorStatus_NONE, data->totalWritten, data->user); }
ILibMemory_Free(data->metadata);
ILibMemory_Free(data); ILibMemory_Free(data);
return(FALSE); return(FALSE);
} }
@@ -3136,13 +3144,16 @@ BOOL ILibChain_WriteEx_Sink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus st
data->totalWritten += data->bytesLeft; data->totalWritten += data->bytesLeft;
data->bytesLeft = 0; data->bytesLeft = 0;
if (data->handler != NULL) { data->handler(chain, data->fileHandle, ILibWaitHandle_ErrorStatus_NONE, data->totalWritten, data->user); } if (data->handler != NULL) { data->handler(chain, data->fileHandle, ILibWaitHandle_ErrorStatus_NONE, data->totalWritten, data->user); }
ILibMemory_Free(data->metadata);
ILibMemory_Free(data); ILibMemory_Free(data);
ret = FALSE; ret = FALSE;
break; break;
case ILibTransport_DoneState_INCOMPLETE: case ILibTransport_DoneState_INCOMPLETE:
ret = TRUE; ret = TRUE;
ILibMemory_Free(data);
case ILibTransport_DoneState_ERROR: case ILibTransport_DoneState_ERROR:
if (data->handler != NULL) { data->handler(chain, data->fileHandle, ILibWaitHandle_ErrorStatus_IO_ERROR, 0, data->user); } if (data->handler != NULL) { data->handler(chain, data->fileHandle, ILibWaitHandle_ErrorStatus_IO_ERROR, 0, data->user); }
ILibMemory_Free(data->metadata);
ILibMemory_Free(data); ILibMemory_Free(data);
ret = FALSE; ret = FALSE;
break; break;
@@ -3161,6 +3172,7 @@ BOOL ILibChain_WriteEx_Sink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus st
{ {
// ERROR // ERROR
if (data->handler != NULL) { data->handler(chain, data->fileHandle, ILibWaitHandle_ErrorStatus_IO_ERROR, 0, data->user); } if (data->handler != NULL) { data->handler(chain, data->fileHandle, ILibWaitHandle_ErrorStatus_IO_ERROR, 0, data->user); }
ILibMemory_Free(data->metadata);
ILibMemory_Free(data); ILibMemory_Free(data);
return(FALSE); return(FALSE);
} }
@@ -3335,6 +3347,11 @@ void __stdcall ILibChain_RemoveWaitHandle_APC(ULONG_PTR u)
{ {
chain->currentHandle = NULL; chain->currentInfo = NULL; chain->currentHandle = NULL; chain->currentInfo = NULL;
} }
ILibChain_WaitHandleInfo *info = (ILibChain_WaitHandleInfo*)ILibMemory_Extra(node);
if (info != NULL)
{
ILibMemory_Free(info->metadata);
}
ILibLinkedList_Remove(node); ILibLinkedList_Remove(node);
chain->UnblockFlag = 1; chain->UnblockFlag = 1;
} }

View File

@@ -998,13 +998,14 @@ int ILibIsRunningOnChainThread(void* chain);
char *metadata; char *metadata;
}ILibChain_WriteEx_data; }ILibChain_WriteEx_data;
char *ILibChain_MetaData(char *file, int number);
void ILibChain_AddWaitHandleEx(void *chain, HANDLE h, int msTIMEOUT, ILibChain_WaitHandleHandler handler, void *user, 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, NULL) #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); void ILibChain_RemoveWaitHandle(void *chain, HANDLE h);
void ILibChain_ReadEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, int bufferLen, ILibChain_ReadEx_Handler handler, void *user, char *metadata); void ILibChain_ReadEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, int bufferLen, ILibChain_ReadEx_Handler handler, void *user, char *metadata);
#define ILibChain_ReadEx(chain, h, overlapped, buffer, bufferLen, handler, user) ILibChain_ReadEx2(chain, h, overlapped, buffer, bufferLen, handler, user, NULL) #define ILibChain_ReadEx(chain, h, overlapped, buffer, bufferLen, handler, user) ILibChain_ReadEx2(chain, h, overlapped, buffer, bufferLen, handler, user, ILibChain_MetaData(__FILE__, __LINE__))
ILibTransport_DoneState ILibChain_WriteEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, int bufferLen, ILibChain_WriteEx_Handler handler, void *user, char *metadata); ILibTransport_DoneState ILibChain_WriteEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, int bufferLen, ILibChain_WriteEx_Handler handler, void *user, char *metadata);
#define ILibChain_WriteEx(chain, h, overlapped, buffer, bufferLen, handler, user) ILibChain_WriteEx2(chain, h, overlapped, buffer, bufferLen, handler, user, NULL) #define ILibChain_WriteEx(chain, h, overlapped, buffer, bufferLen, handler, user) ILibChain_WriteEx2(chain, h, overlapped, buffer, bufferLen, handler, user, ILibChain_MetaData(__FILE__, __LINE__))
#define tv2LTtv1(ptv1, ptv2) ((ptv2)->tv_sec < (ptv1)->tv_sec || ((ptv2)->tv_sec == (ptv1)->tv_sec && (ptv2)->tv_usec < (ptv1)->tv_usec)) #define tv2LTtv1(ptv1, ptv2) ((ptv2)->tv_sec < (ptv1)->tv_sec || ((ptv2)->tv_sec == (ptv1)->tv_sec && (ptv2)->tv_usec < (ptv1)->tv_usec))
#define tv2LTEtv1(ptv1, ptv2) (tv2LTtv1(ptv2,ptv1) || ((ptv2)->tv_sec == (ptv1)->tv_sec && (ptv2)->tv_usec <= (ptv1)->tv_usec)) #define tv2LTEtv1(ptv1, ptv2) (tv2LTtv1(ptv2,ptv1) || ((ptv2)->tv_sec == (ptv1)->tv_sec && (ptv2)->tv_usec <= (ptv1)->tv_usec))

View File

@@ -95,6 +95,7 @@ typedef struct ILibProcessPipe_PipeObject
OVERLAPPED *mOverlapped,*mwOverlapped; OVERLAPPED *mOverlapped,*mwOverlapped;
int inProgress; int inProgress;
void *mOverlapped_opaqueData, *user3, *user4; void *mOverlapped_opaqueData, *user3, *user4;
char *metadata;
#else #else
int mPipe_ReadEnd, mPipe_WriteEnd; int mPipe_ReadEnd, mPipe_WriteEnd;
#endif #endif
@@ -1184,7 +1185,7 @@ BOOL ILibProcessPipe_Process_Pipe_ReadExHandler(void *chain, HANDLE h, ILibWaitH
ILibMemory_ReallocateRaw(&(pipeObject->buffer), pipeObject->bufferSize * 2); ILibMemory_ReallocateRaw(&(pipeObject->buffer), pipeObject->bufferSize * 2);
pipeObject->bufferSize = pipeObject->bufferSize * 2; pipeObject->bufferSize = pipeObject->bufferSize * 2;
} }
ILibChain_ReadEx(chain, h, pipeObject->mOverlapped, pipeObject->buffer + pipeObject->readOffset + pipeObject->totalRead, pipeObject->bufferSize - pipeObject->totalRead, ILibProcessPipe_Process_Pipe_ReadExHandler, pipeObject); ILibChain_ReadEx2(chain, h, pipeObject->mOverlapped, pipeObject->buffer + pipeObject->readOffset + pipeObject->totalRead, pipeObject->bufferSize - pipeObject->totalRead, ILibProcessPipe_Process_Pipe_ReadExHandler, pipeObject, pipeObject->metadata);
return(TRUE); return(TRUE);
} }
else else
@@ -1199,19 +1200,20 @@ BOOL ILibProcessPipe_Process_Pipe_ReadExHandler(void *chain, HANDLE h, ILibWaitH
} }
} }
#endif #endif
void ILibProcessPipe_Process_StartPipeReader(ILibProcessPipe_PipeObject *pipeObject, int bufferSize, ILibProcessPipe_GenericReadHandler handler, void* user1, void* user2) 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); } if ((pipeObject->buffer = (char*)malloc(bufferSize)) == NULL) { ILIBCRITICALEXIT(254); }
pipeObject->bufferSize = bufferSize; pipeObject->bufferSize = bufferSize;
pipeObject->handler = (void*)handler; pipeObject->handler = (void*)handler;
pipeObject->user1 = user1; pipeObject->user1 = user1;
pipeObject->user2 = user2; pipeObject->user2 = user2;
pipeObject->metadata = metadata;
#ifdef WIN32 #ifdef WIN32
if (pipeObject->mOverlapped != NULL) if (pipeObject->mOverlapped != NULL)
{ {
// This PIPE supports Overlapped I/O // This PIPE supports Overlapped I/O
ILibChain_ReadEx(pipeObject->manager->ChainLink.ParentChain, pipeObject->mPipe_ReadEnd, pipeObject->mOverlapped, pipeObject->buffer, pipeObject->bufferSize, ILibProcessPipe_Process_Pipe_ReadExHandler, pipeObject); ILibChain_ReadEx2(pipeObject->manager->ChainLink.ParentChain, pipeObject->mPipe_ReadEnd, pipeObject->mOverlapped, pipeObject->buffer, pipeObject->bufferSize, ILibProcessPipe_Process_Pipe_ReadExHandler, pipeObject, metadata);
} }
else else
{ {
@@ -1310,12 +1312,12 @@ void ILibProcessPipe_Process_AddHandlers(ILibProcessPipe_Process module, int buf
j->userObject = user; j->userObject = user;
j->exitHandler = exitHandler; j->exitHandler = exitHandler;
ILibProcessPipe_Process_StartPipeReader(j->stdOut, bufferSize, &ILibProcessPipe_Process_PipeHandler_StdOut, j, stdOut); ILibProcessPipe_Process_StartPipeReaderEx(j->stdOut, bufferSize, &ILibProcessPipe_Process_PipeHandler_StdOut, j, stdOut, "process_handle_stdout");
ILibProcessPipe_Process_StartPipeReader(j->stdErr, bufferSize, &ILibProcessPipe_Process_PipeHandler_StdOut, j, stdErr); 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); ILibProcessPipe_Process_SetWriteHandler(j->stdIn, &ILibProcessPipe_Process_PipeHandler_StdIn, j, sendOk);
#ifdef WIN32 #ifdef WIN32
ILibChain_AddWaitHandle(j->parent->ChainLink.ParentChain, j->hProcess, -1, ILibProcessPipe_Process_OnExit, j); ILibChain_AddWaitHandleEx(j->parent->ChainLink.ParentChain, j->hProcess, -1, ILibProcessPipe_Process_OnExit, j, "process_handle_exit");
#endif #endif
} }
} }

View File

@@ -90,6 +90,8 @@ void ILibProcessPipe_Process_CloseStdIn(ILibProcessPipe_Process p);
void ILibProcessPipe_Process_GetWaitHandles(ILibProcessPipe_Process p, HANDLE *hProcess, HANDLE *read, HANDLE *write, HANDLE *error); void ILibProcessPipe_Process_GetWaitHandles(ILibProcessPipe_Process p, HANDLE *hProcess, HANDLE *read, HANDLE *write, HANDLE *error);
#endif #endif
#define ILibProcessPipe_Process_StartPipeReader(pipeObject, bufferSize, handler, user1, user2) ILibProcessPipe_Process_StartPipeReaderEx(pipeObject, bufferSize, handler, user1, user2, ILibChain_MetaData(__FILE__, __LINE__))
void ILibProcessPipe_Pipe_Close(ILibProcessPipe_Pipe po); void ILibProcessPipe_Pipe_Close(ILibProcessPipe_Pipe po);
void ILibProcessPipe_Pipe_Pause(ILibProcessPipe_Pipe pipeObject); void ILibProcessPipe_Pipe_Pause(ILibProcessPipe_Pipe pipeObject);
void ILibProcessPipe_Pipe_Resume(ILibProcessPipe_Pipe pipeObject); void ILibProcessPipe_Pipe_Resume(ILibProcessPipe_Pipe pipeObject);