[WIP/FIX] Lock write operations to XMPP

I *think* that fixes stream errors with two threads writing at once.
Even if it doesn't, I think it's always a nice-to-have.
This commit is contained in:
LDA 2024-06-23 17:54:58 +02:00
commit 37155316b2
4 changed files with 32 additions and 0 deletions

View file

@ -17,6 +17,9 @@ XMPPQueryMUC(XMPPComponent *jabber, char *muc, MUCInfo *out)
{
return false;
}
pthread_mutex_lock(&jabber->write_lock);
iq_query = XMLCreateTag("iq");
query = XMLCreateTag("query");
@ -47,6 +50,7 @@ XMPPQueryMUC(XMPPComponent *jabber, char *muc, MUCInfo *out)
{
XMLFreeElement(iq_query);
ParseeWakeupThread();
pthread_mutex_unlock(&jabber->write_lock);
return false;
}
query = XMLookForUnique(iq_query, "query");
@ -58,6 +62,7 @@ XMPPQueryMUC(XMPPComponent *jabber, char *muc, MUCInfo *out)
{
XMLFreeElement(iq_query);
ParseeWakeupThread();
pthread_mutex_unlock(&jabber->write_lock);
return false;
}
@ -74,6 +79,7 @@ XMPPQueryMUC(XMPPComponent *jabber, char *muc, MUCInfo *out)
}
}
/* Wake it up once we're done */
pthread_mutex_unlock(&jabber->write_lock);
ParseeWakeupThread();
return true;
}