Skip sending rather than immediately close while publishing
This commit is contained in:
@@ -60,18 +60,22 @@ struct WebSocketContextData {
|
|||||||
/* We rely on writing to regular asyncSockets */
|
/* We rely on writing to regular asyncSockets */
|
||||||
auto *asyncSocket = (AsyncSocket<SSL> *) s->user;
|
auto *asyncSocket = (AsyncSocket<SSL> *) s->user;
|
||||||
|
|
||||||
auto [written, failed] = asyncSocket->write(data.data(), (int) data.length());
|
/* Check if we now have too much backpressure (todo: don't buffer up before check) */
|
||||||
if (!failed) {
|
if (!maxBackpressure || (unsigned int) asyncSocket->getBufferedAmount() < maxBackpressure) {
|
||||||
asyncSocket->timeout(this->idleTimeout);
|
|
||||||
} else {
|
|
||||||
/* Note: this assumes we are not corked, as corking will swallow things and fail later on */
|
|
||||||
|
|
||||||
/* Check if we now have too much backpressure (todo: don't buffer up before check) */
|
/* Note: this assumes we are not corked, as corking will swallow things and fail later on */
|
||||||
if ((unsigned int) asyncSocket->getBufferedAmount() > maxBackpressure) {
|
auto [written, failed] = asyncSocket->write(data.data(), (int) data.length());
|
||||||
asyncSocket->close();
|
if (!failed) {
|
||||||
|
asyncSocket->timeout(this->idleTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Failing here must not immediately close the socket, as that could result in stack overflow,
|
||||||
|
* iterator invalidation and other TopicTree::drain bugs. We may shutdown the reading side of the socket,
|
||||||
|
* causing next iteration to error-close the socket from that context instead, if we want to */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we have too much backpressure, simply skip sending from here */
|
||||||
|
|
||||||
/* Reserved, unused */
|
/* Reserved, unused */
|
||||||
return 0;
|
return 0;
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user