1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-19 01:33:18 +00:00

1. Updated ILibProcessPipe, so that buffer will grow as necessary

2. Updated Windows KVM, to add an accumulator for JUMBO commands
This commit is contained in:
Bryan Roe
2019-02-06 16:32:31 -08:00
parent 8d8099f0d4
commit ae72740a18
2 changed files with 38 additions and 17 deletions

View File

@@ -1010,12 +1010,27 @@ void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int b
if (bufferLen > 4) if (bufferLen > 4)
{ {
size = ntohs(((unsigned short*)(buffer))[1]); if (ntohs(((unsigned short*)(buffer))[0]) == (unsigned short)MNG_JUMBO)
if (size <= bufferLen)
{ {
*bytesConsumed = size; if (bufferLen > 8)
writeHandler(buffer, size, reserved); {
return; if (bufferLen >= (8 + (int)ntohl(((unsigned int*)(buffer))[1])))
{
*bytesConsumed = 8 + (int)ntohl(((unsigned int*)(buffer))[1]);
writeHandler(buffer, *bytesConsumed, reserved);
return;
}
}
}
else
{
size = ntohs(((unsigned short*)(buffer))[1]);
if (size <= bufferLen)
{
*bytesConsumed = size;
writeHandler(buffer, size, reserved);
return;
}
} }
} }
*bytesConsumed = 0; *bytesConsumed = 0;

View File

@@ -958,14 +958,13 @@ void ILibProcessPipe_Process_ReadHandler(void* user)
result = GetOverlappedResult(pipeObject->mPipe_ReadEnd, pipeObject->mOverlapped, &bytesRead, FALSE); result = GetOverlappedResult(pipeObject->mPipe_ReadEnd, pipeObject->mOverlapped, &bytesRead, FALSE);
if (result == FALSE) { break; } if (result == FALSE) { break; }
#else #else
bytesRead = (int)read(pipeObject->mPipe_ReadEnd, pipeObject->buffer + 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)
{ {
break; break;
} }
#endif #endif
pipeObject->totalRead += bytesRead; pipeObject->totalRead += bytesRead;
ILibRemoteLogging_printf(ILibChainGetLogger(pipeObject->manager->ChainLink.ParentChain), ILibRemoteLogging_Modules_Microstack_Pipe, ILibRemoteLogging_Flags_VerbosityLevel_5, "ILibProcessPipe[ReadHandler]: %u bytes read on Pipe: %p", bytesRead, (void*)pipeObject); ILibRemoteLogging_printf(ILibChainGetLogger(pipeObject->manager->ChainLink.ParentChain), ILibRemoteLogging_Modules_Microstack_Pipe, ILibRemoteLogging_Flags_VerbosityLevel_5, "ILibProcessPipe[ReadHandler]: %u bytes read on Pipe: %p", bytesRead, (void*)pipeObject);
@@ -983,8 +982,7 @@ void ILibProcessPipe_Process_ReadHandler(void* user)
{ {
consumed = 0; consumed = 0;
ILibRemoteLogging_printf(ILibChainGetLogger(pipeObject->manager->ChainLink.ParentChain), ILibRemoteLogging_Modules_Microstack_Generic, ILibRemoteLogging_Flags_VerbosityLevel_5, "ProcessPipe: buffer/%p offset/%d totalRead/%d", (void*)pipeObject->buffer, pipeObject->readOffset, pipeObject->totalRead); ILibRemoteLogging_printf(ILibChainGetLogger(pipeObject->manager->ChainLink.ParentChain), ILibRemoteLogging_Modules_Microstack_Generic, ILibRemoteLogging_Flags_VerbosityLevel_5, "ProcessPipe: buffer/%p offset/%d totalRead/%d", (void*)pipeObject->buffer, pipeObject->readOffset, pipeObject->totalRead);
((ILibProcessPipe_GenericReadHandler)pipeObject->handler)(pipeObject->buffer + pipeObject->readOffset, pipeObject->totalRead, &consumed, pipeObject->user1, pipeObject->user2);
((ILibProcessPipe_GenericReadHandler)pipeObject->handler)(pipeObject->buffer + pipeObject->readOffset, pipeObject->totalRead - pipeObject->readOffset, &consumed, pipeObject->user1, pipeObject->user2);
if (consumed == 0) if (consumed == 0)
{ {
// //
@@ -995,13 +993,12 @@ void ILibProcessPipe_Process_ReadHandler(void* user)
// //
// We need to move the memory to the start of the buffer, or else we risk running past the end, if we keep reading like this // We need to move the memory to the start of the buffer, or else we risk running past the end, if we keep reading like this
// //
memmove_s(pipeObject->buffer, pipeObject->bufferSize, pipeObject->buffer + pipeObject->readOffset, pipeObject->totalRead - pipeObject->readOffset); memmove_s(pipeObject->buffer, pipeObject->bufferSize, pipeObject->buffer + pipeObject->readOffset, pipeObject->totalRead);
pipeObject->totalRead -= pipeObject->readOffset;
pipeObject->readOffset = 0; pipeObject->readOffset = 0;
break; // Break out of inner while loop break; // Break out of inner while loop
} }
else if (consumed == (pipeObject->totalRead - pipeObject->readOffset)) else if (consumed == pipeObject->totalRead)
{ {
// //
// Entire Buffer was consumed // Entire Buffer was consumed
@@ -1018,12 +1015,21 @@ void ILibProcessPipe_Process_ReadHandler(void* user)
// Only part of the buffer was consumed // Only part of the buffer was consumed
// //
pipeObject->readOffset += consumed; pipeObject->readOffset += consumed;
pipeObject->totalRead -= consumed;
} }
} }
if (pipeObject->bufferSize - pipeObject->totalRead == 0)
{
pipeObject->buffer = (char*)realloc(pipeObject->buffer, pipeObject->bufferSize * 2);
if (pipeObject->buffer == NULL) { ILIBCRITICALEXIT(254); }
pipeObject->bufferSize = pipeObject->bufferSize * 2;
}
if (pipeObject->PAUSED != 0) { break; } if (pipeObject->PAUSED != 0) { break; }
} }
#ifdef WIN32 #ifdef WIN32
while ((result = ReadFile(pipeObject->mPipe_ReadEnd, pipeObject->buffer, pipeObject->bufferSize, NULL, pipeObject->mOverlapped)) == TRUE); // Note: This is actually the end of a do-while loop while ((result = ReadFile(pipeObject->mPipe_ReadEnd, pipeObject->buffer + pipeObject->readOffset + pipeObject->totalRead, pipeObject->bufferSize - pipeObject->totalRead, NULL, pipeObject->mOverlapped)) == TRUE); // Note: This is actually the end of a do-while loop
if (pipeObject->PAUSED == 0 && (err = GetLastError()) != ERROR_IO_PENDING) if (pipeObject->PAUSED == 0 && (err = GetLastError()) != ERROR_IO_PENDING)
#else #else
while(pipeObject->PAUSED == 0); // Note: This is actually the end of a do-while loop while(pipeObject->PAUSED == 0); // Note: This is actually the end of a do-while loop
@@ -1207,7 +1213,7 @@ void ILibProcessPipe_Pipe_ResumeEx_ContinueProcessing(ILibProcessPipe_PipeObject
while (p->readOffset != 0 && p->PAUSED == 0) while (p->readOffset != 0 && p->PAUSED == 0)
{ {
consumed = 0; consumed = 0;
((ILibProcessPipe_GenericReadHandler)p->handler)(p->buffer + p->readOffset, p->totalRead - p->readOffset, &consumed, p->user1, p->user2); ((ILibProcessPipe_GenericReadHandler)p->handler)(p->buffer + p->readOffset, p->totalRead, &consumed, p->user1, p->user2);
if (consumed == 0) if (consumed == 0)
{ {
// //
@@ -1218,11 +1224,10 @@ void ILibProcessPipe_Pipe_ResumeEx_ContinueProcessing(ILibProcessPipe_PipeObject
// //
// We need to move the memory to the start of the buffer, or else we risk running past the end, if we keep reading like this // We need to move the memory to the start of the buffer, or else we risk running past the end, if we keep reading like this
// //
memmove_s(p->buffer, p->bufferSize, p->buffer + p->readOffset, p->totalRead - p->readOffset); memmove_s(p->buffer, p->bufferSize, p->buffer + p->readOffset, p->totalRead);
p->totalRead -= p->readOffset;
p->readOffset = 0; p->readOffset = 0;
} }
else if (consumed == (p->totalRead - p->readOffset)) else if (consumed == p->totalRead)
{ {
// //
// Entire Buffer was consumed // Entire Buffer was consumed
@@ -1239,6 +1244,7 @@ void ILibProcessPipe_Pipe_ResumeEx_ContinueProcessing(ILibProcessPipe_PipeObject
// Only part of the buffer was consumed // Only part of the buffer was consumed
// //
p->readOffset += consumed; p->readOffset += consumed;
p->totalRead -= consumed;
} }
} }
p->processingLoop = 0; p->processingLoop = 0;