summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-08-25 17:08:20 -0700
committerLance Stout <lancestout@gmail.com>2011-08-25 17:08:20 -0700
commite3e985220e9599ed34158acc61866619e8f06308 (patch)
tree1e1df3852790e4923a14e42472a4feae70acb91a /sleekxmpp/xmlstream
parent802dd8393d83c9aaa4f2f87f6fdaabbd8d9b8cdf (diff)
downloadslixmpp-e3e985220e9599ed34158acc61866619e8f06308.tar.gz
slixmpp-e3e985220e9599ed34158acc61866619e8f06308.tar.bz2
slixmpp-e3e985220e9599ed34158acc61866619e8f06308.tar.xz
slixmpp-e3e985220e9599ed34158acc61866619e8f06308.zip
Simplify the main process loop.
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index 6f2ed304..3175d92b 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -235,7 +235,6 @@ class XMLStream(object):
self._id_lock = threading.Lock()
self.auto_reconnect = True
- self.is_client = False
self.dns_answers = []
self.add_event_handler('connected', self._handle_connected)
@@ -328,7 +327,6 @@ class XMLStream(object):
except Socket.error:
self.default_domain = self.address[0]
- self.is_client = True
# Respect previous SSL and TLS usage directives.
if use_ssl is not None:
self.use_ssl = use_ssl
@@ -1038,44 +1036,48 @@ class XMLStream(object):
Processing will continue after any recoverable errors
if reconnections are allowed.
"""
- firstrun = True
# The body of this loop will only execute once per connection.
# Additional passes will be made only if an error occurs and
# reconnecting is permitted.
- while firstrun or (self.auto_reconnect and not self.stop.isSet()):
- firstrun = False
+ while True:
try:
- if self.is_client:
- self.send_raw(self.stream_header, now=True)
# The call to self.__read_xml will block and prevent
# the body of the loop from running until a disconnect
# occurs. After any reconnection, the stream header will
# be resent and processing will resume.
- while not self.stop.isSet() and self.__read_xml():
+ while not self.stop.is_set():
+ # Only process the stream while connected to the server
+ if not self.state.ensure('connected', wait=0.1,
+ block_on_transition=True):
+ continue
# Ensure the stream header is sent for any
# new connections.
- if self.is_client:
+ if not self.session_started_event.is_set():
self.send_raw(self.stream_header, now=True)
+ self.__read_xml()
except KeyboardInterrupt:
log.debug("Keyboard Escape Detected in _process")
self.stop.set()
except SystemExit:
log.debug("SystemExit in _process")
self.stop.set()
+ self.scheduler.quit()
except Socket.error as serr:
self.event('socket_error', serr)
log.exception('Socket Error')
except:
- if not self.stop.isSet():
+ if not self.stop.is_set():
log.exception('Connection error.')
- if not self.stop.isSet() and self.auto_reconnect:
- self.reconnect()
+
+ if not self.stop.is_set():
+ if self.auto_reconnect:
+ self.reconnect()
+ else:
+ continue
else:
- self.event('killed', direct=True)
self.disconnect()
- self.event_queue.put(('quit', None, None))
- self.scheduler.run = False
+ break
def __read_xml(self):
"""