Skip to content

Commit d4ffead

Browse files
committed
closeOnBackpressure should block all further sending
1 parent 43a1f30 commit d4ffead

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/WebSocket.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,17 @@ struct WebSocket : AsyncSocket<SSL> {
9494
(us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this)
9595
);
9696

97+
/* If we already reached the max backpressure and started a deferred close, reject all sends */
98+
if (webSocketContextData->closeOnBackpressureLimit == 2) {
99+
return DROPPED;
100+
}
101+
97102
/* Skip sending and report success if we are over the limit of maxBackpressure */
98103
if (webSocketContextData->maxBackpressure && webSocketContextData->maxBackpressure < getBufferedAmount()) {
99104
/* Also defer a close if we should */
100-
if (webSocketContextData->closeOnBackpressureLimit) {
105+
if (webSocketContextData->closeOnBackpressureLimit == 1) {
101106
us_socket_shutdown_read(SSL, (us_socket_t *) this);
107+
webSocketContextData->closeOnBackpressureLimit = 2;
102108
}
103109
return DROPPED;
104110
}

src/WebSocketContextData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ struct WebSocketContextData {
7373

7474
/* There needs to be a maxBackpressure which will force close everything over that limit */
7575
size_t maxBackpressure = 0;
76-
bool closeOnBackpressureLimit;
76+
unsigned char closeOnBackpressureLimit; /* 0, 1 (or 2 internally) */
7777
bool resetIdleTimeoutOnSend;
7878
bool sendPingsAutomatically;
7979

0 commit comments

Comments
 (0)