Add large non-ssl, non-compressed WebSocket message sending optimization
This commit is contained in:
@@ -105,6 +105,23 @@ public:
|
|||||||
|
|
||||||
/* If we are subscribers and have messages to drain we need to drain them here to stay synced */
|
/* If we are subscribers and have messages to drain we need to drain them here to stay synced */
|
||||||
WebSocketData *webSocketData = (WebSocketData *) Super::getAsyncSocketData();
|
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[14];
|
||||||
|
int header_length = (int) protocol::formatMessage<isServer>(header, nullptr, 0, opCode, message.length(), compress, fin);
|
||||||
|
int written = us_socket_write2(0, (struct us_socket_t *)this, header, header_length, message.data(), (int) message.length());
|
||||||
|
|
||||||
|
if (written != header_length + (int) message.length()) {
|
||||||
|
/* Buffer up backpressure */
|
||||||
|
if (written > header_length) {
|
||||||
|
webSocketData->buffer.append(message.data() + written, message.length() - (size_t) written);
|
||||||
|
} else {
|
||||||
|
webSocketData->buffer.append(header + written, (size_t) header_length - (size_t) written);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
if (webSocketData->subscriber) {
|
if (webSocketData->subscriber) {
|
||||||
/* This will call back into us, send. */
|
/* This will call back into us, send. */
|
||||||
webSocketContextData->topicTree->drain(webSocketData->subscriber);
|
webSocketContextData->topicTree->drain(webSocketData->subscriber);
|
||||||
@@ -149,6 +166,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* Every successful send resets the timeout */
|
/* Every successful send resets the timeout */
|
||||||
if (webSocketContextData->resetIdleTimeoutOnSend) {
|
if (webSocketContextData->resetIdleTimeoutOnSend) {
|
||||||
Super::timeout(webSocketContextData->idleTimeoutComponents.first);
|
Super::timeout(webSocketContextData->idleTimeoutComponents.first);
|
||||||
|
|||||||
+1
-1
Submodule uSockets updated: b950efd6b1...0866daff30
Reference in New Issue
Block a user