Skip sending on WebSocket when having too much backpressure
This commit is contained in:
+10
-4
@@ -58,6 +58,15 @@ public:
|
|||||||
|
|
||||||
/* Send or buffer a WebSocket frame, compressed or not. Returns false on increased user space backpressure. */
|
/* Send or buffer a WebSocket frame, compressed or not. Returns false on increased user space backpressure. */
|
||||||
bool send(std::string_view message, uWS::OpCode opCode = uWS::OpCode::BINARY, bool compress = false) {
|
bool send(std::string_view message, uWS::OpCode opCode = uWS::OpCode::BINARY, bool compress = false) {
|
||||||
|
WebSocketContextData<SSL> *webSocketContextData = (WebSocketContextData<SSL> *) us_socket_context_ext(SSL,
|
||||||
|
(us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this)
|
||||||
|
);
|
||||||
|
|
||||||
|
/* Skip sending and report success if we are over the limit of maxBackpressure */
|
||||||
|
if (webSocketContextData->maxBackpressure < getBufferedAmount()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Transform the message to compressed domain if requested */
|
/* Transform the message to compressed domain if requested */
|
||||||
if (compress) {
|
if (compress) {
|
||||||
WebSocketData *webSocketData = (WebSocketData *) Super::getAsyncSocketData();
|
WebSocketData *webSocketData = (WebSocketData *) Super::getAsyncSocketData();
|
||||||
@@ -109,10 +118,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Every successful send resets the timeout */
|
/* Every successful send resets the timeout */
|
||||||
WebSocketContextData<SSL> *webSocketContextData = (WebSocketContextData<SSL> *) us_socket_context_ext(SSL,
|
Super::timeout(webSocketContextData->idleTimeout);
|
||||||
(us_socket_context_t *) us_socket_context(SSL, (us_socket_t *) this)
|
|
||||||
);
|
|
||||||
AsyncSocket<SSL>::timeout(webSocketContextData->idleTimeout);
|
|
||||||
|
|
||||||
/* Return success */
|
/* Return success */
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user