summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2015-04-14 17:54:16 +0200
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2015-04-14 19:14:56 +0200
commitd34ddf33db361eb39193ca4231bc56c60af5ddac (patch)
treed7a65126637c162e853a2514eb6b8b589d95eb15
parenteb4e09b0ca2f699405c448ae7e4b818ff72ea301 (diff)
downloadslixmpp-d34ddf33db361eb39193ca4231bc56c60af5ddac.tar.gz
slixmpp-d34ddf33db361eb39193ca4231bc56c60af5ddac.tar.bz2
slixmpp-d34ddf33db361eb39193ca4231bc56c60af5ddac.tar.xz
slixmpp-d34ddf33db361eb39193ca4231bc56c60af5ddac.zip
XEP-0047: replace threading events with simple booleans.
-rw-r--r--slixmpp/plugins/xep_0047/ibb.py4
-rw-r--r--slixmpp/plugins/xep_0047/stream.py24
2 files changed, 13 insertions, 15 deletions
diff --git a/slixmpp/plugins/xep_0047/ibb.py b/slixmpp/plugins/xep_0047/ibb.py
index d1c708ed..be452877 100644
--- a/slixmpp/plugins/xep_0047/ibb.py
+++ b/slixmpp/plugins/xep_0047/ibb.py
@@ -142,7 +142,7 @@ class XEP_0047(BasePlugin):
log.debug('IBB stream (%s) accepted by %s', stream.sid, iq['from'])
stream.self_jid = iq['to']
stream.peer_jid = iq['from']
- stream.stream_started.set()
+ stream.stream_started = True
self.api['set_stream'](stream.self_jid, stream.sid, stream.peer_jid, stream)
self.xmpp.event('ibb_stream_start', stream)
self.xmpp.event('stream:%s:%s' % (stream.sid, stream.peer_jid), stream)
@@ -167,7 +167,7 @@ class XEP_0047(BasePlugin):
stream = IBBytestream(self.xmpp, sid, size,
iq['to'], iq['from'])
- stream.stream_started.set()
+ stream.stream_started = True
self.api['set_stream'](stream.self_jid, stream.sid, stream.peer_jid, stream)
iq.reply().send()
diff --git a/slixmpp/plugins/xep_0047/stream.py b/slixmpp/plugins/xep_0047/stream.py
index 9c9d82a5..9b7426a9 100644
--- a/slixmpp/plugins/xep_0047/stream.py
+++ b/slixmpp/plugins/xep_0047/stream.py
@@ -1,5 +1,4 @@
import socket
-import threading
import logging
from queue import Queue
@@ -26,15 +25,14 @@ class IBBytestream(object):
self.send_seq = -1
self.recv_seq = -1
- self.stream_started = threading.Event()
- self.stream_in_closed = threading.Event()
- self.stream_out_closed = threading.Event()
+ self.stream_started = False
+ self.stream_in_closed = False
+ self.stream_out_closed = False
self.recv_queue = Queue()
def send(self, data):
- if not self.stream_started.is_set() or \
- self.stream_out_closed.is_set():
+ if not self.stream_started or self.stream_out_closed:
raise socket.error
data = data[0:self.block_size]
self.send_seq = (self.send_seq + 1) % 65535
@@ -90,8 +88,7 @@ class IBBytestream(object):
return self.read(block=True)
def read(self, block=True, timeout=None, **kwargs):
- if not self.stream_started.is_set() or \
- self.stream_in_closed.is_set():
+ if not self.stream_started or self.stream_in_closed:
raise socket.error
if timeout is not None:
block = True
@@ -106,14 +103,15 @@ class IBBytestream(object):
iq['to'] = self.peer_jid
iq['from'] = self.self_jid
iq['ibb_close']['sid'] = self.sid
- self.stream_out_closed.set()
- iq.send(block=False,
- callback=lambda x: self.stream_in_closed.set())
+ self.stream_out_closed = True
+ def _close_stream(_):
+ self.stream_in_closed = True
+ iq.send(block=False, callback=_close_stream)
self.xmpp.event('ibb_stream_end', self)
def _closed(self, iq):
- self.stream_in_closed.set()
- self.stream_out_closed.set()
+ self.stream_in_closed = True
+ self.stream_out_closed = True
iq.reply().send()
self.xmpp.event('ibb_stream_end', self)