mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-06 00:13:33 +00:00
Fixed crash/exception that could occur if you shutdown the agent while a websocket is connected
This commit is contained in:
@@ -4259,6 +4259,7 @@ ILibTransport_DoneState ILibDuktape_httpStream_webSocket_EncodedWriteSink(ILibDu
|
||||
void ILibDuktape_httpStream_webSocket_EncodedEndSink(ILibDuktape_DuplexStream *stream, void *user)
|
||||
{
|
||||
ILibDuktape_WebSocket_State *state = (ILibDuktape_WebSocket_State*)user;
|
||||
if (duk_ctx_shutting_down(state->ctx)) { return; }
|
||||
if (!state->closed) { ILibDuktape_DuplexStream_WriteEnd(state->decodedStream); }
|
||||
}
|
||||
void ILibDuktape_httpStream_webSocket_EncodedPauseSink_Chain(void *chain, void *user)
|
||||
@@ -4373,6 +4374,8 @@ void ILibDuktape_httpStream_webSocket_DecodedPauseSink_Chain(void *chain, void *
|
||||
void ILibDuktape_httpStream_webSocket_DecodedPauseSink(ILibDuktape_DuplexStream *sender, void *user)
|
||||
{
|
||||
ILibDuktape_WebSocket_State *state = (ILibDuktape_WebSocket_State*)user;
|
||||
if (state == NULL || state->encodedStream == NULL || state->encodedStream->writableStream == NULL) { return; } // ERROR
|
||||
|
||||
if (state->encodedStream->writableStream->pipedReadable_native != NULL && state->encodedStream->writableStream->pipedReadable_native->PauseHandler != NULL)
|
||||
{
|
||||
state->encodedStream->writableStream->pipedReadable_native->paused = 1;
|
||||
|
||||
@@ -825,6 +825,7 @@ duk_ret_t ILibDuktape_readableStream_unpipe(duk_context *ctx)
|
||||
int nargs = duk_get_top(ctx);
|
||||
int onlyItem = 0;
|
||||
ILibDuktape_readableStream *data;
|
||||
if (duk_ctx_shutting_down(ctx)) { return(0); }
|
||||
|
||||
duk_push_this(ctx); // [readable]
|
||||
duk_get_prop_string(ctx, -1, ILibDuktape_readableStream_RSPTRS); // [readable][ptrs]
|
||||
@@ -851,24 +852,26 @@ duk_ret_t ILibDuktape_readableStream_unpipe(duk_context *ctx)
|
||||
duk_pop_2(ctx); // [readable]
|
||||
}
|
||||
sem_post(&(data->pipeLock));
|
||||
|
||||
if (nargs == 0 || onlyItem != 0)
|
||||
{
|
||||
// We need to pause first
|
||||
duk_push_this(ctx); // [readable]
|
||||
duk_get_prop_string(ctx, -1, "pause"); // [readable][pause]
|
||||
duk_dup(ctx, -2); // [readable][pause][this]
|
||||
duk_call_method(ctx, 0); duk_pop(ctx); // [readable]
|
||||
}
|
||||
|
||||
// We must yield, and do this on the next event loop, because we can't unpipe if we're called from a pipe'ed call
|
||||
void *imm = ILibDuktape_Immediate(ctx, (void*[]) { duk_get_heapptr(ctx, -1), nargs == 1 ? duk_get_heapptr(ctx, 0) : NULL }, nargs + 1, ILibDuktape_readableStream_unpipe_later);
|
||||
duk_push_heapptr(ctx, imm); // [immediate]
|
||||
duk_push_this(ctx); // [immediate][this]
|
||||
duk_put_prop_string(ctx, -2, "\xFF_Self"); // [immediate]
|
||||
if (nargs == 1) { duk_dup(ctx, 0); duk_put_prop_string(ctx, -2, "\xFF_w"); }
|
||||
duk_pop(ctx); // ...
|
||||
|
||||
if (duk_ctx_shutting_down(ctx) == 0)
|
||||
{
|
||||
if (nargs == 0 || onlyItem != 0)
|
||||
{
|
||||
// We need to pause first
|
||||
duk_push_this(ctx); // [readable]
|
||||
duk_get_prop_string(ctx, -1, "pause"); // [readable][pause]
|
||||
duk_dup(ctx, -2); // [readable][pause][this]
|
||||
duk_call_method(ctx, 0); duk_pop(ctx); // [readable]
|
||||
}
|
||||
|
||||
// We must yield, and do this on the next event loop, because we can't unpipe if we're called from a pipe'ed call
|
||||
void *imm = ILibDuktape_Immediate(ctx, (void*[]) { duk_get_heapptr(ctx, -1), nargs == 1 ? duk_get_heapptr(ctx, 0) : NULL }, nargs + 1, ILibDuktape_readableStream_unpipe_later);
|
||||
duk_push_heapptr(ctx, imm); // [immediate]
|
||||
duk_push_this(ctx); // [immediate][this]
|
||||
duk_put_prop_string(ctx, -2, "\xFF_Self"); // [immediate]
|
||||
if (nargs == 1) { duk_dup(ctx, 0); duk_put_prop_string(ctx, -2, "\xFF_w"); }
|
||||
duk_pop(ctx); // ...
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
duk_ret_t ILibDuktape_readableStream_isPaused(duk_context *ctx)
|
||||
|
||||
Reference in New Issue
Block a user