Stricter pub/sub grouping
This commit is contained in:
@@ -217,6 +217,11 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If this topic is triggered, drain the tree before we join */
|
||||||
|
if (iterator->triggered) {
|
||||||
|
drain();
|
||||||
|
}
|
||||||
|
|
||||||
/* Add socket to Topic's Set */
|
/* Add socket to Topic's Set */
|
||||||
auto [it, inserted] = iterator->subs.insert(subscriber);
|
auto [it, inserted] = iterator->subs.insert(subscriber);
|
||||||
|
|
||||||
@@ -253,6 +258,11 @@ public:
|
|||||||
/* Try and remove this topic from our list */
|
/* Try and remove this topic from our list */
|
||||||
for (auto it = subscriber->subscriptions.begin(); it != subscriber->subscriptions.end(); it++) {
|
for (auto it = subscriber->subscriptions.begin(); it != subscriber->subscriptions.end(); it++) {
|
||||||
if (*it == iterator) {
|
if (*it == iterator) {
|
||||||
|
/* If this topic is triggered, drain the tree before we leave */
|
||||||
|
if (iterator->triggered) {
|
||||||
|
drain();
|
||||||
|
}
|
||||||
|
|
||||||
/* Remove topic ptr from our list */
|
/* Remove topic ptr from our list */
|
||||||
subscriber->subscriptions.erase(it);
|
subscriber->subscriptions.erase(it);
|
||||||
|
|
||||||
@@ -270,6 +280,17 @@ public:
|
|||||||
void unsubscribeAll(Subscriber *subscriber) {
|
void unsubscribeAll(Subscriber *subscriber) {
|
||||||
if (subscriber) {
|
if (subscriber) {
|
||||||
for (Topic *topic : subscriber->subscriptions) {
|
for (Topic *topic : subscriber->subscriptions) {
|
||||||
|
|
||||||
|
/* This is questionable; we are called mostly from socket close, so we will
|
||||||
|
* potentially call drain callback with a closed socket, make sure to check there!
|
||||||
|
* Well it doesn't really matter since there are checks in uSockets but still! */
|
||||||
|
|
||||||
|
/* If this topic is triggered, drain the tree before we leave */
|
||||||
|
if (topic->triggered) {
|
||||||
|
drain();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove us from the topic's set */
|
||||||
topic->subs.erase(subscriber);
|
topic->subs.erase(subscriber);
|
||||||
trimTree(topic);
|
trimTree(topic);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,13 @@ 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;
|
||||||
|
|
||||||
|
/* We might be called from unsubscribeAll from close handler of a socket,
|
||||||
|
* so make sure to check if we are a closed socket before trying to send */
|
||||||
|
if (us_socket_is_closed(SSL, (struct us_socket_t *) s->user) || us_socket_is_shut_down(SSL, (struct us_socket_t *) s->user)) {
|
||||||
|
/* Return code means nothing, todo: remove it */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if we now have too much backpressure (todo: don't buffer up before check) */
|
/* Check if we now have too much backpressure (todo: don't buffer up before check) */
|
||||||
if (!maxBackpressure || (unsigned int) asyncSocket->getBufferedAmount() < maxBackpressure) {
|
if (!maxBackpressure || (unsigned int) asyncSocket->getBufferedAmount() < maxBackpressure) {
|
||||||
/* Pick uncompressed data track */
|
/* Pick uncompressed data track */
|
||||||
|
|||||||
Reference in New Issue
Block a user