Lock client buffers while writing
This commit is contained in:
parent
cae82bd107
commit
66061d5fb2
|
@ -39,7 +39,8 @@ class token:
|
||||||
self.loginTime = int(time.time())
|
self.loginTime = int(time.time())
|
||||||
self.pingTime = self.loginTime
|
self.pingTime = self.loginTime
|
||||||
self.timeOffset = timeOffset
|
self.timeOffset = timeOffset
|
||||||
self.lock = threading.Lock() # Sync primitive
|
self.lock = threading.Lock()
|
||||||
|
self.bufferLock = threading.Lock()
|
||||||
self.streams = []
|
self.streams = []
|
||||||
self.tournament = tournament
|
self.tournament = tournament
|
||||||
self.messagesBuffer = []
|
self.messagesBuffer = []
|
||||||
|
@ -102,6 +103,8 @@ class token:
|
||||||
|
|
||||||
:param bytes_: (packet) bytes to enqueue
|
:param bytes_: (packet) bytes to enqueue
|
||||||
"""
|
"""
|
||||||
|
# Acquire the buffer lock
|
||||||
|
self.bufferLock.acquire()
|
||||||
|
|
||||||
# Never enqueue for IRC clients or Foka
|
# Never enqueue for IRC clients or Foka
|
||||||
if self.irc or self.userID < 999:
|
if self.irc or self.userID < 999:
|
||||||
|
@ -113,9 +116,14 @@ class token:
|
||||||
else:
|
else:
|
||||||
log.warning("{}'s packets buffer is above 10M!! Lost some data!".format(self.username))
|
log.warning("{}'s packets buffer is above 10M!! Lost some data!".format(self.username))
|
||||||
|
|
||||||
|
# Release the buffer lock
|
||||||
|
self.bufferLock.release()
|
||||||
|
|
||||||
def resetQueue(self):
|
def resetQueue(self):
|
||||||
"""Resets the queue. Call when enqueued packets have been sent"""
|
"""Resets the queue. Call when enqueued packets have been sent"""
|
||||||
|
self.bufferLock.acquire()
|
||||||
self.queue = bytes()
|
self.queue = bytes()
|
||||||
|
self.bufferLock.release()
|
||||||
|
|
||||||
def joinChannel(self, channelObject):
|
def joinChannel(self, channelObject):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user