mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-17 16:53:13 +00:00
Updated ReadEx
This commit is contained in:
@@ -93,7 +93,6 @@ typedef struct ILibDuktape_net_WindowsIPC
|
||||
|
||||
ULONG_PTR _reserved[5];
|
||||
|
||||
int processingRead;
|
||||
char *buffer;
|
||||
int bufferLength;
|
||||
int bufferOffset;
|
||||
@@ -847,14 +846,10 @@ int ILibDuktape_net_server_IPC_unshiftSink(ILibDuktape_DuplexStream *sender, int
|
||||
winIPC->unshiftedBytes = unshiftBytes;
|
||||
return(unshiftBytes);
|
||||
}
|
||||
void ILibDuktape_net_server_IPC_readsink_safe(void *chain, void *user)
|
||||
void ILibDuktape_net_server_IPC_readsink(ILibProcessPipe_Pipe sender, void *user, DWORD dwErrorCode, char *buffer, int bufferLen)
|
||||
{
|
||||
if (!ILibMemory_CanaryOK(user)) { return; }
|
||||
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
|
||||
ILibProcessPipe_Pipe sender = (ILibProcessPipe_Pipe)winIPC->_reserved[0];
|
||||
DWORD dwErrorCode = (DWORD)winIPC->_reserved[2];
|
||||
char *buffer = (char*)winIPC->_reserved[3];
|
||||
int bufferLen = (int)winIPC->_reserved[4];
|
||||
|
||||
if (dwErrorCode == 0)
|
||||
{
|
||||
@@ -895,19 +890,6 @@ void ILibDuktape_net_server_IPC_readsink_safe(void *chain, void *user)
|
||||
}
|
||||
}
|
||||
}
|
||||
void ILibDuktape_net_server_IPC_readsink(ILibProcessPipe_Pipe sender, void *user, DWORD dwErrorCode, char *buffer, int bufferLen)
|
||||
{
|
||||
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
|
||||
if (!ILibMemory_CanaryOK(user)) { return; }
|
||||
|
||||
winIPC->_reserved[0] = (ULONG_PTR)sender;
|
||||
winIPC->_reserved[1] = (ULONG_PTR)user;
|
||||
winIPC->_reserved[2] = (ULONG_PTR)dwErrorCode;
|
||||
winIPC->_reserved[3] = (ULONG_PTR)buffer;
|
||||
winIPC->_reserved[4] = (ULONG_PTR)bufferLen;
|
||||
|
||||
Duktape_RunOnEventLoop(winIPC->mChain, duk_ctx_nonce(winIPC->ctx), winIPC->ctx, ILibDuktape_net_server_IPC_readsink_safe, NULL, winIPC);
|
||||
}
|
||||
void ILibDuktape_net_server_IPC_PauseSink(ILibDuktape_DuplexStream *sender, void *user)
|
||||
{
|
||||
// No-OP, becuase all we need to so is set Paused flag, which is already the case when we get here
|
||||
@@ -915,8 +897,7 @@ void ILibDuktape_net_server_IPC_PauseSink(ILibDuktape_DuplexStream *sender, void
|
||||
void ILibDuktape_net_server_IPC_ResumeSink(ILibDuktape_DuplexStream *sender, void *user)
|
||||
{
|
||||
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
|
||||
if (winIPC->processingRead != 0 || winIPC->mPipeHandle == NULL) { return; }
|
||||
winIPC->processingRead = 1;
|
||||
if (winIPC->mPipeHandle == NULL) { return; }
|
||||
|
||||
if (winIPC->buffer == NULL)
|
||||
{
|
||||
@@ -982,7 +963,6 @@ void ILibDuktape_net_server_IPC_ResumeSink(ILibDuktape_DuplexStream *sender, voi
|
||||
}
|
||||
}
|
||||
}
|
||||
winIPC->processingRead = 0;
|
||||
}
|
||||
void ILibDuktape_net_server_IPC_WriteCompletionEvent(ILibProcessPipe_Pipe sender, void *user, DWORD errorCode, int bytesWritten)
|
||||
{
|
||||
|
||||
@@ -1851,23 +1851,58 @@ int ILibProcessPipe_Pipe_CancelEx(ILibProcessPipe_Pipe targetPipe)
|
||||
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;
|
||||
DWORD bytesRead = 0;
|
||||
|
||||
if (GetOverlappedResult(j->mPipe_ReadEnd, j->mOverlapped, &bytesRead, FALSE))
|
||||
{
|
||||
if (j->user2 != NULL) { ((ILibProcessPipe_Pipe_ReadExHandler)j->user2)(j, j->user1, 0, j->buffer, (int)bytesRead); }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GetLastError() == ERROR_IO_PENDING)
|
||||
{
|
||||
return(TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (j->user2 != NULL) { ((ILibProcessPipe_Pipe_ReadExHandler)j->user2)(j, j->user1, 1, j->buffer, 0); }
|
||||
}
|
||||
}
|
||||
|
||||
return(FALSE);
|
||||
}
|
||||
int ILibProcessPipe_Pipe_ReadEx(ILibProcessPipe_Pipe targetPipe, char *buffer, int bufferLength, void *user, ILibProcessPipe_Pipe_ReadExHandler OnReadHandler)
|
||||
{
|
||||
ILibProcessPipe_PipeObject *j = (ILibProcessPipe_PipeObject*)targetPipe;
|
||||
DWORD bytesRead = 0;
|
||||
int ret = 0;
|
||||
|
||||
if (ReadFile(j->mPipe_ReadEnd, buffer, bufferLength, &bytesRead, j->mOverlapped))
|
||||
{
|
||||
// Complete
|
||||
if (OnReadHandler != NULL) { OnReadHandler(j, user, 0, buffer, (int)bytesRead); }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GetLastError() == ERROR_IO_PENDING)
|
||||
{
|
||||
j->usingCompletionRoutine = 1;
|
||||
j->buffer = buffer;
|
||||
j->bufferSize = bufferLength;
|
||||
j->user1 = user;
|
||||
j->user2 = OnReadHandler;
|
||||
if (!ReadFileEx(j->mPipe_ReadEnd, j->buffer, j->bufferSize, j->mOverlapped, ILibProcessPipe_Pipe_Read_CompletionRoutine))
|
||||
{
|
||||
return(GetLastError());
|
||||
ILibChain_AddWaitHandle(j->manager->ChainLink.ParentChain, j->mOverlapped->hEvent, -1, ILibProcessPipe_Pipe_ReadEx_sink, j);
|
||||
}
|
||||
else
|
||||
{
|
||||
return(0);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
BOOL ILibProcessPipe_Pipe_WriteEx_sink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, void* user)
|
||||
{
|
||||
ILibProcessPipe_PipeObject *j = (ILibProcessPipe_PipeObject*)user;
|
||||
|
||||
Reference in New Issue
Block a user