[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

@ -76,6 +76,7 @@ XMPPInitialiseCompStream(char *host, int port)
comp = Malloc(sizeof(*comp));
comp->host = StrDuplicate(host);
comp->stream = stream;
pthread_mutex_init(&comp->write_lock, NULL);
return comp;
}
@ -112,6 +113,8 @@ XMPPAuthenticateCompStream(XMPPComponent *comp, char *shared)
return false;
}
pthread_mutex_lock(&comp->write_lock);
stream = comp->stream;
as = comp->host;
StreamPrintf(stream,
@ -178,6 +181,7 @@ XMPPAuthenticateCompStream(XMPPComponent *comp, char *shared)
Free(handshake);
end:
XMLFreeLexer(sax);
pthread_mutex_unlock(&comp->write_lock);
return ret;
}
@ -188,6 +192,7 @@ XMPPEndCompStream(XMPPComponent *comp)
{
return;
}
pthread_mutex_destroy(&comp->write_lock);
StreamClose(comp->stream);
Free(comp->host);
Free(comp);