mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-01-06 02:23:59 +00:00
Added ability to Save/Restore handle wait state
Fixed edge case that could cause a connection to resume twice
This commit is contained in:
@@ -701,6 +701,8 @@ duk_ret_t ILibDuktape_readableStream_pipe(duk_context *ctx)
|
||||
duk_call_method(ctx, 2); duk_pop(ctx); // ...
|
||||
if (rstream->paused != 0)
|
||||
{
|
||||
rstream->paused = 0; // Set state now, so nobody tries to resume before we can finish piping
|
||||
|
||||
// We are paused, so we should yield and resume... We yield, so in case the user tries to chain multiple pipes, it will chain first
|
||||
rstream->resumeImmediate = ILibDuktape_Immediate(ctx, (void*[]) { rstream, duk_get_heapptr(ctx, 0) }, 1, ILibDuktape_ReadableStream_pipe_ResumeLater);
|
||||
duk_push_heapptr(ctx, rstream->resumeImmediate); // [immediate]
|
||||
|
||||
@@ -94,7 +94,7 @@ typedef struct ILibDuktape_net_WindowsIPC
|
||||
OVERLAPPED overlapped;
|
||||
ILibDuktape_DuplexStream *ds;
|
||||
BOOL clientConnected;
|
||||
|
||||
void *reservedState;
|
||||
ULONG_PTR _reserved[5];
|
||||
|
||||
char *buffer;
|
||||
@@ -947,12 +947,22 @@ void ILibDuktape_net_server_IPC_PauseSink(ILibDuktape_DuplexStream *sender, void
|
||||
// No-OP, becuase all we need to so is set Paused flag, which is already the case when we get here
|
||||
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
|
||||
winIPC->paused = 1;
|
||||
|
||||
winIPC->reservedState = ILibChain_WaitHandle_RemoveAndSaveState(winIPC->mChain, winIPC->read_overlapped.hEvent);
|
||||
}
|
||||
void ILibDuktape_net_server_IPC_ResumeSink(ILibDuktape_DuplexStream *sender, void *user)
|
||||
{
|
||||
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
|
||||
winIPC->paused = 0;
|
||||
ILibDuktape_server_ipc_ReadSink(winIPC->mChain, winIPC->mPipeHandle, ILibWaitHandle_ErrorStatus_NONE, NULL, 0, winIPC);
|
||||
if (winIPC->reservedState != NULL)
|
||||
{
|
||||
ILibChain_WaitHandle_RestoreState(winIPC->mChain, winIPC->reservedState);
|
||||
winIPC->reservedState = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ILibDuktape_server_ipc_ReadSink(winIPC->mChain, winIPC->mPipeHandle, ILibWaitHandle_ErrorStatus_NONE, NULL, 0, winIPC);
|
||||
}
|
||||
}
|
||||
|
||||
ILibTransport_DoneState ILibDuktape_net_server_IPC_WriteSink(ILibDuktape_DuplexStream *stream, char *buffer, int bufferLen, void *user)
|
||||
|
||||
Reference in New Issue
Block a user