From c35d6c1bb828ca8c00f1303c7b22e38b8999cd14 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sun, 12 Sep 2021 16:48:47 +0200 Subject: [PATCH] Add more checks and warnings for cork buffer misuse --- src/AsyncSocket.h | 4 +++- src/Loop.h | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/AsyncSocket.h b/src/AsyncSocket.h index b092ea9..04ad5f1 100644 --- a/src/AsyncSocket.h +++ b/src/AsyncSocket.h @@ -25,6 +25,7 @@ * to signal error with -1 (which is how the entire UNIX syscalling is built). */ #include +#include #include "libusockets.h" @@ -82,7 +83,8 @@ protected: void cork() { /* Extra check for invalid corking of others */ if (getLoopData()->corkOffset && getLoopData()->corkedSocket != this) { - std::abort(); + std::cerr << "Error: Cork buffer must not be acquired without checking canCork!" << std::endl; + std::terminate(); } /* What if another socket is corked? */ diff --git a/src/Loop.h b/src/Loop.h index 305cc2d..da3023b 100644 --- a/src/Loop.h +++ b/src/Loop.h @@ -22,6 +22,7 @@ #include "LoopData.h" #include +#include namespace uWS { struct Loop { @@ -56,6 +57,12 @@ private: for (auto &p : loopData->postHandlers) { p.second((Loop *) loop); } + + /* After every event loop iteration, we must not hold the cork buffer */ + if (loopData->corkedSocket) { + std::cerr << "Error: Cork buffer must not be held across event loop iterations!" << std::endl; + std::terminate(); + } } Loop() = delete;