Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/WebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,29 @@
WebSocketContextData<SSL, USERDATA> *webSocketContextData = (WebSocketContextData<SSL, USERDATA> *) us_socket_context_ext(SSL,
(us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this)
);
WebSocketData *webSocketData = (WebSocketData *) Super::getAsyncSocketData();

/* Once closing due to backpressure, never send another frame */
if (webSocketData->isClosingDueToBackpressure) {
return DROPPED;
}

/* Skip sending and report success if we are over the limit of maxBackpressure */
/* Skip sending if we are over the limit of maxBackpressure */
if (webSocketContextData->maxBackpressure && webSocketContextData->maxBackpressure < getBufferedAmount()) {
/* Also defer a close if we should */
if (webSocketContextData->closeOnBackpressureLimit) {
webSocketData->isClosingDueToBackpressure = true;
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 */
/* Inform the application about the triggering dropped message */
if (webSocketContextData->droppedHandler) {
webSocketContextData->droppedHandler(this, message, opCode);
}

return DROPPED;
}

/* If we are subscribers and have messages to drain we need to drain them here to stay synced */
WebSocketData *webSocketData = (WebSocketData *) Super::getAsyncSocketData();

/* Special path for long sends of non-compressed, non-SSL messages */
if (message.length() >= 16 * 1024 && !compress && !SSL && !webSocketData->subscriber && getBufferedAmount() == 0 && Super::getLoopData()->corkOffset == 0) {
char header[10];
Expand All @@ -156,9 +160,10 @@
}
} else {

/* If we are subscribers and have messages to drain we need to drain them here to stay synced */
if (webSocketData->subscriber) {
/* This will call back into us, send. */
webSocketContextData->topicTree->drain(webSocketData->subscriber);

Check notice

Code scanning / CodeQL

Declaration hides variable Note

Variable webSocketData hides another variable of the same name (on
line 135
).
}

/* Transform the message to compressed domain if requested */
Expand Down
2 changes: 1 addition & 1 deletion src/WebSocketContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ struct WebSocketContext {
auto *webSocketData = (WebSocketData *)(us_socket_ext(SSL, s));
auto *webSocketContextData = (WebSocketContextData<SSL, USERDATA> *) us_socket_context_ext(SSL, us_socket_context(SSL, (us_socket_t *) s));

if (webSocketContextData->sendPingsAutomatically && !webSocketData->isShuttingDown && !webSocketData->hasTimedOut) {
if (webSocketContextData->sendPingsAutomatically && !webSocketData->isShuttingDown && !webSocketData->isClosingDueToBackpressure && !webSocketData->hasTimedOut) {
webSocketData->hasTimedOut = true;
us_socket_timeout(SSL, s, webSocketContextData->idleTimeoutComponents.second);
/* Send ping without being corked */
Expand Down
1 change: 1 addition & 0 deletions src/WebSocketData.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct WebSocketData : AsyncSocketData<false>, WebSocketState<true> {
std::string fragmentBuffer;
unsigned int controlTipLength = 0;
bool isShuttingDown = 0;
bool isClosingDueToBackpressure = false;
bool hasTimedOut = false;
enum CompressionStatus : char {
DISABLED,
Expand Down
Loading