summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorTeddy <[email protected]>2013-08-29 09:48:13 +0800
committerTeddy <[email protected]>2013-08-29 09:48:13 +0800
commit016af459bb7148e6115e9013107f583b67c14469 (patch)
tree71f0a2e0ec67c23fd794cc18c76a6eb4bb5b90b0 /server
parent8f1982baf087949df2ac6492235b411a7cfdf59f (diff)
fixed activation & deactivation problem
Diffstat (limited to 'server')
-rw-r--r--server/piztor/mesg_sender.py1
-rw-r--r--server/piztor/server.py23
2 files changed, 16 insertions, 8 deletions
diff --git a/server/piztor/mesg_sender.py b/server/piztor/mesg_sender.py
index e3ad6e4..e9135bd 100644
--- a/server/piztor/mesg_sender.py
+++ b/server/piztor/mesg_sender.py
@@ -21,3 +21,4 @@ if len(argv) == 4:
uid, token = user_auth(username, password)
send_text_mesg(token, username, mesg)
+logout(token, username)
diff --git a/server/piztor/server.py b/server/piztor/server.py
index a58a301..ae79c76 100644
--- a/server/piztor/server.py
+++ b/server/piztor/server.py
@@ -84,9 +84,9 @@ class PushTunnel(object):
self.pending = deque()
self.conn = None
- def __del__(self):
+ def close(self):
if self.conn:
- self.conn.loseConnection()
+ self.conn.transport.loseConnection()
def add(self, pdata):
logger.info("-- Push data enqued --")
@@ -97,7 +97,7 @@ class PushTunnel(object):
length, optcode, fingerprint = struct.unpack("!LB32s", data)
if front.finger_print != fingerprint:
raise PiztorError
- logger.info("-- Push data confirmed --")
+ logger.info("-- Push data confirmed by client --")
self.push()
def push(self):
@@ -112,12 +112,15 @@ class PushTunnel(object):
self.conn.transport.write(front.data)
def connect(self, conn):
- print conn
conn.tunnel = self
+ if self.conn: # only one long-connection per user
+ self.conn.transport.loseConnection()
self.conn = conn
- def on_connection_lost(self):
- self.conn = None
+ def on_connection_lost(self, conn):
+ if conn == self.conn:
+ print "*** clear conn ***"
+ self.conn = None
class RequestHandler(object):
push_tunnels = dict()
@@ -436,7 +439,10 @@ class UserLogoutHandler(RequestHandler):
return struct.pack("!LBB", self._response_size,
_OptCode.user_logout,
_StatusCode.failure)
- del RequestHandler.push_tunnels[uauth.uid]
+ pt = RequestHandler.push_tunnels
+ uid = uauth.uid
+ pt[uid].close()
+ del pt[uid]
uauth.regen_token()
logger.info("User Logged out successfully!")
self.session.commit()
@@ -534,6 +540,7 @@ class SendTextMessageHandler(RequestHandler):
if pt.has_key(uid):
tunnel = pt[uid]
tunnel.add(PushTextMesgData(mesg))
+ tunnel.push()
logger.info("Sent text mesg successfully!")
return struct.pack("!LBB", self._response_size,
_OptCode.send_text_mesg,
@@ -621,7 +628,7 @@ class PTP(Protocol, TimeoutMixin):
def connectionLost(self, reason):
if self.tunnel:
- self.tunnel.on_connection_lost()
+ self.tunnel.on_connection_lost(self)
logger.info("The connection is lost")
self.setTimeout(None)