Browse Source

reworked CMClient conn drop handling; fix #21

pull/34/head
Rossen Georgiev 9 years ago
parent
commit
ae8326f591
  1. 8
      steam/client/__init__.py
  2. 8
      steam/core/cm.py
  3. 6
      steam/core/connection.py

8
steam/client/__init__.py

@ -35,6 +35,7 @@ class SteamClient(EventEmitter, FeatureBase):
# register listners
self.cm.on(None, self._handle_cm_events)
self.cm.on("disconnected", self._handle_disconnect)
self.cm.on("reconnect", self._handle_disconnect)
self.on(EMsg.ClientLogOnResponse, self._handle_logon)
self.on(EMsg.ClientUpdateMachineAuth, self._handle_update_machine_auth)
@ -86,6 +87,7 @@ class SteamClient(EventEmitter, FeatureBase):
"""
Close connection
"""
self.logged_on = False
self.cm.disconnect()
def _handle_cm_events(self, event, *args):
@ -102,7 +104,11 @@ class SteamClient(EventEmitter, FeatureBase):
if jobid not in (-1, 18446744073709551615):
self.emit("job_%d" % jobid, *args)
def _handle_disconnect(self):
def _handle_disconnect(self, *args):
# only disconnect, reconnect has 1 arg
if self.logged_on and len(args) == 0:
gevent.spawn(self.connect)
self.username = None
self.logged_on = False
self.current_jobid = 0

8
steam/core/cm.py

@ -60,8 +60,6 @@ class CMClient(EventEmitter):
else:
raise ValueError("Only TCP is supported")
self.connection.event_connected.rawlink(self._handle_disconnect)
self.on(EMsg.ChannelEncryptRequest, self._handle_encrypt_request),
self.on(EMsg.Multi, self._handle_multi),
self.on(EMsg.ClientLogOnResponse, self._handle_logon),
@ -95,10 +93,6 @@ class CMClient(EventEmitter):
self.emit("connected")
self._recv_loop = gevent.spawn(self._recv_messages)
def _handle_disconnect(self, event):
if not event.is_set():
gevent.spawn(self.disconnect)
def disconnect(self, reconnect=False, nodelay=False):
"""Close connection
@ -208,6 +202,8 @@ class CMClient(EventEmitter):
gevent.spawn(self._parse_message, message)
gevent.idle()
gevent.spawn(self.disconnect)
def _parse_message(self, message):
emsg_id, = struct.unpack_from("<I", message)
emsg = EMsg(clear_proto_bit(emsg_id))

6
steam/core/connection.py

@ -51,6 +51,7 @@ class Connection(object):
def disconnect(self):
if not self.event_connected.is_set():
return
self.event_connected.clear()
self.server_addr = None
@ -70,11 +71,6 @@ class Connection(object):
logger.debug("Disconnected.")
# hack
# rawlink will only call the callback on set
self.event_connected.set()
self.event_connected.clear()
def __iter__(self):
return self.recv_queue

Loading…
Cancel
Save