From 7f94456669afa52411897f9194b866b09fdcaa1e Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Mon, 29 Aug 2022 15:11:04 +0200 Subject: [PATCH] Hook up onAborted, fix a bunch of quic crashes --- src/Http3Context.h | 19 ++++++++++++------- src/Http3ResponseData.h | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Http3Context.h b/src/Http3Context.h index f6d5664ec..930164d48 100644 --- a/src/Http3Context.h +++ b/src/Http3Context.h @@ -22,7 +22,7 @@ namespace uWS { // we don't have a way to know EOF? Http3ResponseData *responseData = (Http3ResponseData *) us_quic_stream_ext(s); - if (responseData) { + if (responseData->onData) { responseData->onData({data, length}, true); } @@ -32,13 +32,18 @@ namespace uWS { //printf("Stream opened!\n"); // inplace initialize Http3ResponseData here + + new (us_quic_stream_ext(s)) Http3ResponseData(); }); us_quic_socket_context_on_close(context, [](us_quic_socket_t *s) { printf("Disconnected!\n"); + }); us_quic_socket_context_on_stream_writable(context, [](us_quic_stream_t *s) { // Http3ResponseData *responseData = us_quic_stream_ext(s); // responseData->onWritable(); + + }); us_quic_socket_context_on_stream_headers(context, [](us_quic_stream_t *s) { @@ -52,19 +57,19 @@ namespace uWS { contextData->router.getUserData() = {(Http3Response *) s, (Http3Request *) nullptr}; contextData->router.route(upperCasedMethod, "/"); - }); us_quic_socket_context_on_open(context, [](us_quic_socket_t *s, int is_client) { printf("Connection established!\n"); }); us_quic_socket_context_on_stream_close(context, [](us_quic_stream_t *s) { - // Http3ResponseData *responseData = us_quic_stream_ext(s); - // responseData->onAborted(); - - //printf("Stream closed\n"); + Http3ResponseData *responseData = (Http3ResponseData *) us_quic_stream_ext(s); + + if (responseData->onAborted) { + responseData->onAborted(); + } - // inplace destruct Http3ResponseData here + responseData->~Http3ResponseData(); }); return (Http3Context *) context; diff --git a/src/Http3ResponseData.h b/src/Http3ResponseData.h index a1c02019b..83adf3573 100644 --- a/src/Http3ResponseData.h +++ b/src/Http3ResponseData.h @@ -7,8 +7,8 @@ namespace uWS { struct Http3ResponseData { - MoveOnlyFunction onAborted; - MoveOnlyFunction onData; + MoveOnlyFunction onAborted = nullptr; + MoveOnlyFunction onData = nullptr; // hasWrittenStatus