Add .dropped events for pub/sub backpressure notification

This commit is contained in:
Alex Hultman
2023-11-30 17:38:12 +01:00
parent bc2815d95b
commit 973a975915
4 changed files with 12 additions and 0 deletions
+3
View File
@@ -38,6 +38,9 @@ int main() {
* benchmarking of large message sending without compression */
ws->send(message, opCode, message.length() < 16 * 1024);
},
.dropped = [](auto */*ws*/, std::string_view /*message*/, uWS::OpCode /*opCode*/) {
/* A message was dropped due to set maxBackpressure and closeOnBackpressureLimit limit */
},
.drain = [](auto */*ws*/) {
/* Check ws->getBufferedAmount() here */
},
+2
View File
@@ -242,6 +242,7 @@ public:
MoveOnlyFunction<void(HttpResponse<SSL> *, HttpRequest *, struct us_socket_context_t *)> upgrade = nullptr;
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *)> open = nullptr;
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *, std::string_view, OpCode)> message = nullptr;
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *, std::string_view, OpCode)> dropped = nullptr;
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *)> drain = nullptr;
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *, std::string_view)> ping = nullptr;
MoveOnlyFunction<void(WebSocket<SSL, true, UserData> *, std::string_view)> pong = nullptr;
@@ -372,6 +373,7 @@ public:
/* Copy all handlers */
webSocketContext->getExt()->openHandler = std::move(behavior.open);
webSocketContext->getExt()->messageHandler = std::move(behavior.message);
webSocketContext->getExt()->droppedHandler = std::move(behavior.dropped);
webSocketContext->getExt()->drainHandler = std::move(behavior.drain);
webSocketContext->getExt()->subscriptionHandler = std::move(behavior.subscription);
webSocketContext->getExt()->closeHandler = std::move([closeHandler = std::move(behavior.close)](WebSocket<SSL, true, UserData> *ws, int code, std::string_view message) mutable {
+6
View File
@@ -100,6 +100,12 @@ public:
if (webSocketContextData->closeOnBackpressureLimit) {
us_socket_shutdown_read(SSL, (us_socket_t *) this);
}
/* It is okay to call send again from within this callback since we immediately return with DROPPED afterwards */
if (webSocketContextData->droppedHandler) {
webSocketContextData->droppedHandler(this, message, opCode);
}
return DROPPED;
}
+1
View File
@@ -59,6 +59,7 @@ public:
/* The callbacks for this context */
MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *)> openHandler = nullptr;
MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view, OpCode)> messageHandler = nullptr;
MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view, OpCode)> droppedHandler = nullptr;
MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *)> drainHandler = nullptr;
MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, std::string_view, int, int)> subscriptionHandler = nullptr;
MoveOnlyFunction<void(WebSocket<SSL, true, USERDATA> *, int, std::string_view)> closeHandler = nullptr;